【发布时间】:2022-01-30 05:33:01
【问题描述】:
我有一个名为carts 的表,其结构如下:
1 crt_id Primary bigint(20)
2 crt_mbr_id bigint(20)
3 crt_session_id varchar(128)
4 crt_content text
5 crt_send_type int(11)
6 crt_completed tinyint(1)
7 created_at timestamp
8 updated_at timestamp
crt_content 的数据是这样的:
[{"id":"24","quantity":"1","price":3000,"discounted":3000,"coupon":0}]
现在我需要在crt_content 中搜索号码24。
所以我尝试了这个:
SELECT JSON_UNQUOTE(JSON_EXTRACT(crt_content, '24')) as scope from carts
但这会给我这个错误:
#3143 - Invalid JSON path expression. The error is around character position 1
那么这里出了什么问题?如何在此 carts 表的 crt_content 字段中正确搜索 24 的 id?
【问题讨论】:
-
确保只使用适用于实际问题的标签。
-
另外参考文档可以减少随机尝试:dev.mysql.com/doc/refman/8.0/en/json-search-functions.html