CosmosDB 过滤器基于数组 属性,大于

CosmosDB filter based on array property, Greater than

我在结构的容器中有一个项目:

{
    "order_id": 6,
    "customer_id": 94,
    "order_status": 4,
    "order_date": "2016-01-04",
    "required_date": "2016-01-07",
    "shipped_date": "2016-01-05",
    "store_id": 2,
    "staff_id": 6,
    "order_details": [
        {
            "order_id": 6,
            "item_id": 1,
            "product_id": 18,
            "quantity": 1,
            "list_price": 449,
            "discount": 0.07
        },
        {
            "order_id": 6,
            "item_id": 2,
            "product_id": 12,
            "quantity": 2,
            "list_price": 549.99,
            "discount": 0.05
        },
        {
            "order_id": 6,
            "item_id": 3,
            "product_id": 20,
            "quantity": 1,
            "list_price": 599.99,
            "discount": 0.1
        },
        {
            "order_id": 6,
            "item_id": 4,
            "product_id": 3,
            "quantity": 2,
            "list_price": 999.99,
            "discount": 0.07
        },
        {
            "order_id": 6,
            "item_id": 5,
            "product_id": 9,
            "quantity": 2,
            "list_price": 2999.99,
            "discount": 0.07
        }
    ],
    "id": "63bfc98b-d7d1-4090-b293-305980e626b0",
    "_rid": "7mM8AIbq5iEEAAAAAAAAAA==",
    "_self": "dbs/7mM8AA==/colls/7mM8AIbq5iE=/docs/7mM8AIbq5iEEAAAAAAAAAA==/",
    "_etag": "\"00000000-0000-0000-248e-8dec8fa101d8\"",
    "_attachments": "attachments/",
    "_ts": 1645164769
}

我想根据 'order_details' 过滤项目。 我可以基于 'item_id' 进行过滤,如下所示:

SELECT * FROM c
where ARRAY_CONTAINS(c.order_details,{"item_id":1},true)

如果我想实现过滤掉折扣(比方说)>0.04 的商品。 如何实现?

你需要的是JOIN查询

SELECT c
FROM c
JOIN details IN c.order_details
WHERE details.discount > 0.05

您需要按照您需要的输出格式进行格式化!