检查范围内的sqlite json数组元素是否
我有一个包含一个带有数组字段的JSON列的表,我想检查数组中的数字是否属于一个范围,即,如果每个元素传递的谓词大于x,并且比y,则比y,
select nom.id, nom.doc
from nom
join json_each(nom.doc, "$.rate") e
where e.value > 0 and e.value < 7
我' d期望这能起作用,但事实并非 想像
依靠聚合,
id: 1, doc: {rate: [1, 2, 3]}
id: 2, doc: {rate: [1, 2, 3, 5 9]}
因为我 我有这两个记录,我想让那些速率值少于7和大于0的记录,例如,ID 2的记录不应出现在我想要的查询中。
I have a table which contains a json column that has an array field, I want to check if the numbers inside the array belong to a range, that is if each element passes the predicate to be greater than X and lesser than Y,
select nom.id, nom.doc
from nom
join json_each(nom.doc, "$.rate") e
where e.value > 0 and e.value < 7
I'd expect this to work but it doesn't, I understand that json_each returns a table, and I think maybe using grouping or aggregation I could get what I want, but I want to know if there is another way, I would like to not rely on aggregation, as I would want to for example, check if all elements pass a predicate, for example, if all are greater than X, or if I where working with strings, if they all match a pattern etc.
sample data:
id: 1, doc: {rate: [1, 2, 3]}
id: 2, doc: {rate: [1, 2, 3, 5 9]}
If I have those two records, I'd like to get those whose rate has values lesser than 7 and greater than 0, for example, record with id 2 should not appear in the query I desire.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是提取CTE内部数组的所有值,并在主查询中使用不存在以检查是否是否某个特定
id> id
通过谓词:更改
&lt;您的谓词&gt;
to以下内容:请参阅演示。
One way to do it is to extract all the values of the array inside a CTE and use
NOT EXISTS
in the main query to check if all values of a certainid
pass the predicate:Change
<your predicate>
to something like:See the demo.