查询 CosmosDB 嵌套结构 JSON
Query CosmosDB nested structure JSON
我正在为我们的一个应用程序使用 CosmosDB SQLAPI。我使用 Azure Storage Explore 进行查询。 JSON 我发现很难查询的结构。
{
"countyid": 0,
"data": [
[
{
"Elements": [
{
"ID": 11,
"V": false,
"R": false
},
{
"ID": 16,
"V": false,
"R": false
},
{
"ID": 3,
"V": false,
"R": false
},
{
"ID": 5,
"V": false,
"R": false
}
]
},
{
"Elements": [
{
"ID": 486,
"V": false,
"R": false
},
{
"ID": 492,
"V": false,
"R": false
}
]
}
]
]
}
我需要获取 Elements[0] ID = 3,5,11,16 和 Elements2 ID = 486,492
CosmosDB Querying JSON edit window
Azure Storage Explorer window trying to query
Query working without where condition
查询嵌套数组数据时需要使用join,请试试这个sql:
SELECT distinct c.data from c
join elem1 in c.data[0].Elements
join elem2 in c.data[1].Elements
where elem1.ID in(3,5,6,11) and elem2.ID in (486,492)
SQL
select value array(select value z.ID from z in a.Elements)
from c
join b in c.data
join a in b
结果
[
[
11,
16,
3,
5
],
[
486,
492
]
]
我正在为我们的一个应用程序使用 CosmosDB SQLAPI。我使用 Azure Storage Explore 进行查询。 JSON 我发现很难查询的结构。
{
"countyid": 0,
"data": [
[
{
"Elements": [
{
"ID": 11,
"V": false,
"R": false
},
{
"ID": 16,
"V": false,
"R": false
},
{
"ID": 3,
"V": false,
"R": false
},
{
"ID": 5,
"V": false,
"R": false
}
]
},
{
"Elements": [
{
"ID": 486,
"V": false,
"R": false
},
{
"ID": 492,
"V": false,
"R": false
}
]
}
]
]
}
我需要获取 Elements[0] ID = 3,5,11,16 和 Elements2 ID = 486,492
CosmosDB Querying JSON edit window
Azure Storage Explorer window trying to query
Query working without where condition
查询嵌套数组数据时需要使用join,请试试这个sql:
SELECT distinct c.data from c
join elem1 in c.data[0].Elements
join elem2 in c.data[1].Elements
where elem1.ID in(3,5,6,11) and elem2.ID in (486,492)
SQL
select value array(select value z.ID from z in a.Elements)
from c
join b in c.data
join a in b
结果
[
[
11,
16,
3,
5
],
[
486,
492
]
]