首页 > 解决方案 > 合并结果 Cosmosdb 中的两个查询

问题描述

SELECT 
count(c.Transaction_Id) as Legacy FROM c where c.OverallStatus = 'COMPLETED' and c.KeyData2 like 'WLS_%'
and contains (c.Created_Date, '2021-08-11') and c.Transaction_Set_Code = '210'
SELECT 
count(c.Transaction_Id) as NonLegacy FROM c where c.OverallStatus = 'COMPLETED' and c.KeyData2 not like 'WLS_%'
and contains (c.Created_Date, '2021-08-11') and c.Transaction_Set_Code = '210'

必填答案:

[
    {
        "Legacy": 18753,
        "NonLegacy": 121862
    }
]

标签: azureazure-cosmosdbazure-cosmosdb-sqlapi

解决方案


Select t.cnt , t.keyd from (
  SELECT count(1) as cnt, c.keydata2 as keyd 
  FROM c 
  where c.OverallStatus = 'COMPLETED' 
  and contains (c.Created_Date, '2021-08-11')
  and c.Transaction_Set_Code = '210'
  group by c.KeyData2)
t
 where t.keyd like 'wls_%' or t.keyd not like 'wls_%'

推荐阅读