SELECT DISTINCT tag, body FROM pages
WHERE (body REGEXP BINARY '"listeListeOuiNon":".*1.*"') AND NOT (body REGEXP BINARY '"listeListeOuiNon":"2"')
表
id uid info
1 1001 {"name":"周年庆","status":0,"addtime":"2017-10-10"}
2 1002 [ {"name":"周年庆","status":0,"addtime":"2017-10-11"},{"name":"特价促销","status":0,"addtime":"2017-10-12"}]
3 1003 [ {"name":"特价促销","status":0,"addtime":"2017-10-12"},{"name":"国庆促销","status":0,"addtime":"2017-09-28"}]
查询语句:select * from tb
where info->'$.name' = '特价促销' or JSON_CONTAINS(info->'$[*].name', '"特价促销"', '$')
查询语句:SELECT * FROM nlu_define_table WHERE
JSON_CONTAINS(JSON_ARRAY("我","想","销","存单"),keywords->'$.keywords') ORDER BY weights DESC
其他查询语句:
SELECT * FROM nlu_define_table
SELECT * FROM nlu_define_table WHERE
keywords LIKE "%销%"
SELECT * FROM nlu_define_table WHERE
JSON_EXTRACT(keywords,'$.keywords') LIKE "%销%"
SELECT * FROM nlu_define_table WHERE
keywords ->'$.keywords' LIKE "%销%"
第三条sql和第四条sql是等效。
MyBatis
select
*
from nlu_define_table
where 1 = 1
AND
'$[*].name', ]]>'"${name}"'
正常来说,使用mysql的JSON_EXTRACT()处理函数就可以了,例如:
SELECT JSON_EXTRACT('{"id":"3"}', "$.id")
可以查询出id字段中包含id为3的,但是会有一个问题,当mysql的使用工具navicat版本过低时,不支持转码或者查询,会报错,这是需要在JSON_EXTRACT外面套一层JSON_UNQUOTE 即可正常使用,语句如下:
SELECT JSON_UNQUOTE(JSON_EXTRACT('{"id":"3"}', "$.id"))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)