![](/img/trans.png)
[英]Mysql where clause query on json column in which array of objects data
[英]Query JSON column with array of objects MySQL
我的專欄中有以下json數組:
[
{
"day": 1,
"requests": 23
},
{
"day": 2,
"requests": 5
},
{
"day": 2,
"requests": 9
}
]
我想要第1
天的那一行。 我已經嘗試過這樣做了
SELECT * FROM api WHERE usages->'$[*].day' = JSON_ARRAY(1)
但它沒有返回任何結果。
select usages->'$[*].day' from api
表明它是JSON數組[1,2,2]
。
where usages->'$[*].day' = JSON_ARRAY(1)
試圖將[1,2,2]
與[1]
匹配,這是不正確的。
而是使用JSON_CONTAINS來查找數組中的值。
where json_contains(usages->'$[*].day', "1");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.