我怎样才能通过 n1ql 查询检索所有的孩子
how can i retrieve all the childrens by n1ql query
我打算检索所有 parent 中的 child 个元素,我如何检索它,在数组 objects 的数组中。
SELECT sd.*
FROM test AS t
UNNEST stateDetails AS sd;
{
"type":"countries",
"docName":"CountryData",
"countryDetails":[
{
"name":"US",
"code":"+1",
"stateInfo":[
{
"name":"Florida",
"id":"1212"
},
{
"name":"NewYork",
"id":"1214"
}
]
},
{
"name":"France",
"code":"+33",
"stateInfo":[
{
"name":"Grand Est",
"id":"5212"
},
{
"name":"Brittany",
"id":"5214"
}
]
}
]
}
我期待以下输出显示所有国家/地区的州详细信息及其各自的国家/地区名称
[
{
"countryName":"US",
"name":"Florida",
"id":"1212"
},
{
"countryName":"US",
"name":"NewYork",
"id":"1214"
},
{
"countryName":"France",
"name":"Grand Est",
"id":"5212"
},
{
"countryName":"France",
"name":"Brittany",
"id":"5214"
}
]
使用双 UNNEST 并根据需要进行投影
SELECT cd.name AS countryName, sd.name, sd.id
FROM test AS t
UNNEST t.countryDetails AS cd
UNNEST cd.stateInfo AS sd
WHERE t.type = "countries";
我打算检索所有 parent 中的 child 个元素,我如何检索它,在数组 objects 的数组中。
SELECT sd.*
FROM test AS t
UNNEST stateDetails AS sd;
{
"type":"countries",
"docName":"CountryData",
"countryDetails":[
{
"name":"US",
"code":"+1",
"stateInfo":[
{
"name":"Florida",
"id":"1212"
},
{
"name":"NewYork",
"id":"1214"
}
]
},
{
"name":"France",
"code":"+33",
"stateInfo":[
{
"name":"Grand Est",
"id":"5212"
},
{
"name":"Brittany",
"id":"5214"
}
]
}
]
}
我期待以下输出显示所有国家/地区的州详细信息及其各自的国家/地区名称
[
{
"countryName":"US",
"name":"Florida",
"id":"1212"
},
{
"countryName":"US",
"name":"NewYork",
"id":"1214"
},
{
"countryName":"France",
"name":"Grand Est",
"id":"5212"
},
{
"countryName":"France",
"name":"Brittany",
"id":"5214"
}
]
使用双 UNNEST 并根据需要进行投影
SELECT cd.name AS countryName, sd.name, sd.id
FROM test AS t
UNNEST t.countryDetails AS cd
UNNEST cd.stateInfo AS sd
WHERE t.type = "countries";