I'm using Mysql 5.7 and it has following data set.
mysql> select id, browser from events;
+----+--------------------------------------------------------------------+
| id | browser |
+----+--------------------------------------------------------------------+
| 1 | [{"price": "10.00", "tag": "60"}, {"price": "25.00", "tag": "20"}] |
| 2 | [{"price": "8.00", "tag": "10"}, {"price": "25.00", "tag": "20 "}] |
+----+--------------------------------------------------------------------+
I want to extract only the following map out of this data set. (Not the whole array list)
{"price": "10.00", "tag": "60"}
I tried following command but provide an empty set.
mysql> select * from events where json_contains(browser->'$[*].price', json_object('price',"10.00"));
Empty set (0.00 sec)
Can someone explain me why it is not working or how to query the map contains price =10.00 ?
SELECT browser,JSON_EXTRACT(browser,"$.price")
FROM events t
WHERE JSON_EXTRACT(browser,"$.price")=10.00
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.