为什么这个 CosmosDB 子查询会失败?

Why does this CosmosDB SubQuery fail?

我正在尝试使用简单的子查询来获取值,但我收到有关基数的错误消息

查询如下:

SELECT va.variantId AS ItemNo,
       c.Season,
       SUBSTRING(va.variantId, 0, 7) AS ProductNo,
       SUBSTRING(va.variantId, 0, 10) AS ArticleNo, 
       SUBSTRING(va.variantId, 0, 13) AS VariantNo,
       (
        SELECT VALUE p["value"]
        FROM c
        JOIN p IN c.OriginalData.presentation.productNameLong
        WHERE c.ItemNo = '123456'
        AND p.locale = 'en-GB'
        AND c.Season = '201808'
        AND c.brand = 'xxx'
        ) AS Title
FROM c
JOIN sm IN c.OriginalData.base.sales.summary.salesMarkets
JOIN ar IN sm.articles
JOIN va IN ar.variants
JOIN ch IN va.channels
WHERE c.ItemNo = '123456'
AND sm.salesMarket = 'SE'
AND ch.channelName = 'xxx'

错误如下:

Failed to query item for container rawdata:
 Gateway Failed to Retrieve Query Plan: Message: {"errors":[{"severity":"Error","location":{"start":227,"end":498},"code":"SC2201","message":"The cardinality of a scalar subquery result set cannot be greater than one."}]}
ActivityId: 11ff3b08-d8a7-4737-9111-81f319cf1dc5, Microsoft.Azure.Documents.Common/2.11.0, Microsoft.Azure.Documents.Common/2.11.0

该子查询的结果只能是 1 个结果,所以我不确定它在抱怨什么

您需要使用 ARRAY 表达式从子查询的结果构造一个数组。

请试试这个SQL:

SELECT va.variantId AS ItemNo,
       c.Season,
       SUBSTRING(va.variantId, 0, 7) AS ProductNo,
       SUBSTRING(va.variantId, 0, 10) AS ArticleNo, 
       SUBSTRING(va.variantId, 0, 13) AS VariantNo,
       ARRAY(
        SELECT VALUE p["value"]
        FROM c
        JOIN p IN c.OriginalData.presentation.productNameLong
        WHERE c.ItemNo = '123456'
        AND p.locale = 'en-GB'
        AND c.Season = '201808'
        AND c.brand = 'xxx'
        ) AS Title
FROM c
JOIN sm IN c.OriginalData.base.sales.summary.salesMarkets
JOIN ar IN sm.articles
JOIN va IN ar.variants
JOIN ch IN va.channels
WHERE c.ItemNo = '123456'
AND sm.salesMarket = 'SE'
AND ch.channelName = 'xxx'