如何在cosmos db中使用联接以获得结果

时间:2019-05-21 12:19:17

标签: azure-cosmosdb

我具有以下结构

{
    "SubscriberId": "a4db02c1-f41b-4ab1-9f3e-83f9a7ccde83",
    "Subscription": {
        "Type": "Member",
        "MaxUsers": "200",
        "StartDate": "2018-07-01T00:00:00.0000000Z",
        "EndDate": "2019-07-31T00:00:00.0000000Z",
        "Families": [
            {
                "Id": "4042e5dc-ff0e-5cca-d5ee-d96c4522f1db",
                "Products": [
                    {
                        "Id": "e9313211-ca18-4776-8fea-1d552b6f40d6",
                        "Price": null
                    },
                    {
                        "Id": "bf3cdaa4-8cbe-42e6-8f6f-20c1210dc4ac",
                        "Price": null
                    }
                ]
            }
        ],
        "IsActive": "true"
    }
}

所以我想以下面的结构获取数据,如何使用sql来做到这一点?

SubscriberID ,  Type,Families.Id,Families.Products.Id, Families.Products.Price

1 个答案:

答案 0 :(得分:0)

请使用sql:

select distinct c.SubscriberId,c.Subscription.Type as Type,
f.Id as FamiliesId,p.Id as ProductsId,p.Price as ProductsPrice
from c
join f in c.Subscription.Families 
join p in f.Products

结果:

enter image description here