【问题标题】:Querying the Cosmos db collection of array data查询数组数据的 Cosmos db 集合
【发布时间】:2019-01-17 20:58:50
【问题描述】:

我是 cosmos 的新手,我有一个想要查询的集合,示例如下。 因为数据是嵌套的,因为它的性质。我们还必须能够查询文档的子部分。

我在尝试检索以下集合中 itemCode 的数据时陷入困境。

任何信息都会有很大帮助。提前致谢。

从 c 中选择 * 其中 c.customerSites.pricingGroup.itemCode ="2400953"

此查询不返回任何结果。

Data collection sample

{
     "customerSites": [
    {
        "customerCode": "196729",
        "businessUnitName": "XXXXX SOUTHERN LTD",
        "siteCode": "96271",
        "addressCode": "_MAINXXXX",
        "pricingGroup": [
            {
                "itemCode": 2400953,
                "branches": [
                    8999,
                    3001,
                    3002,
                    3003,
                    3004
                ],
                "rates": [
                    {
                        "branchCodes": [
                            8999,
                            3001,
                            3002,
                            3003
                        ],
                        "discountPercentage": null,
                        "derivedRateId": 77735584,
                        "derivedRateClassification": "customrate",
                        "branchLevel": 109,
                        "derivedRateType": "P",
                        "durationRates": [
                            {
                                "durationType": 1,
                                "rate": 125
                            }
                        ]
                    }
                ]
            }
        ]
    }
],
"id": "196729",
"dataType": "AccountCustomer",
"_ts": 1547161022

}

【问题讨论】:

  • 这里没有问题。你试过了吗?
  • 请不要包含任何指向您的示例数据的链接。这里很多人不会点击链接。而是以formatted text 的形式为您提供样本
  • 是尼克,因为我正在格式化数据。以便我的问题可见。
  • @Vready - 不清楚您的查询是什么。请编辑您的问题以显示您的实际查询以及您遇到的问题。
  • @DavidMakogon 我正在尝试获取集合中可以在 itemCode 上过滤的值。

标签: sql azure-cosmosdb azure-cosmosdb-sqlapi


【解决方案1】:

简单地做:

SELECT * FROM c where c.customerSites[0].pricingGroup[0].itemCode = 2400953

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    • 2019-02-17
    • 1970-01-01
    • 2018-03-30
    相关资源
    最近更新 更多