我刚刚发现了alasql,它太棒了!但是我不确定这是一个已知的限制还是我的查询有问题,但是由于某种原因,我无法使用下面的查询在下面的JSON中找到值“algb 2b-gb”。看起来如果没有提到数组中项的确切位置,那么查询将无法给予结果。这是一个已知的限制还是有更好的方法来查询数组项?
感谢你的想法。
下面是SQL查询:
SELECT COUNT( * ) FROM ? WHERE profile->ad_site_permissions->0 = "algb2b-gb"
下面是我的JSON
[{
"id": "00u1fcghdvmRWnNb81d8",
"profile": {
"lastName": "AUvalidation",
"ad_site_permissions": [
"algb2b-us",
"algb2b-it",
"algb2b-de",
"algb2b-au",
"algb2b-nz",
"algb2b-nl",
"algb2b-fr",
"algb2b-gb",
"algb2b-es",
"algb2b-pr",
"algb2b-ca",
"algb2b-br",
"algb2b-ch"
],
"ad_system_permissions": [
"bpReadAccess",
"ecomReadAccess"
]
}
}, {
"id": "00u2zvh77sVZMACHYLIZ",
"profile": {
"ad_site_permissions": [
"algb2b-ca",
"algb2b-fr",
"algb2b-it",
"algb2b-de",
"algb2b-nl",
"algb2b-au",
"algb2b-nz",
"algb2b-gb",
"algb2b-es",
"algb2b-br"
],
"ad_system_permissions": [
"bpReadAccess",
"ecomReadAccess"
]
}
}]
我的输出是
[
{
"COUNT(*)": 0
}
]
但是,如果我改变我的查询如下,那么它的工作:
SELECT COUNT( * ) FROM ? WHERE profile->ad_site_permissions->7 = "algb2b-gb"
访问github站点获取文档。
1条答案
按热度按时间8i9zcol21#
上面的查询将检查
ad_site_permissions[0]
数组项的计数,该数组项为algb 2b-us,并且不等于algb 2b-gb,因此计数为0。您可以优化查询以搜索数组的所有索引,例如:
所以你可以试试这样