我已经到处寻找,看看是否有人需要这个,但找不到太多。
我在Azure DocumentDB集合中有以下json对象:
{
personID: 1,
name: "Bruce",
surname: "Dickinson",
items: [
{
itemID: 1,
itemType: "A",
name: 'Item 1'
},
{
itemID: 2,
itemType: "A",
name: 'Item 2'
},
{
itemID: 3,
itemType: "B",
name: 'Item 3'
}
]
}这个集合中有很多人。personID 2、3、4 ......100....1000等等。
我想编写一个SQL查询来提取personID =1和itemType = 'A‘项的itemID数组。我希望结果看起来像这样:
itemIDs: [
1,
2
]或者简单地说:
[
1,
2
]以前有没有人尝试过这样做?这有可能吗?
发布于 2017-09-11 19:24:27
比我熟悉SQL foo的人可能知道只用SQL就能做到这一点,但我会使用用户定义函数(UDF)来做到这一点。
下面是SQL语句:
SELECT VALUE udf.getItemIDArray(c) FROM collection c WHERE <your clause>下面是UDF可能的样子:
function getItemIDArray (o) {
output = [];
for (item in o.items) {
output.push(item.itemID)
}
return output
}https://stackoverflow.com/questions/46154197
复制相似问题