SQL,JSON查询-
Posted -levi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL,JSON查询-相关的知识,希望对你有一定的参考价值。
表
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
<![CDATA[ JSON_CONTAINS( info->‘$[*].name‘, ]]> '"$name"' <![CDATA[ , ‘$‘ ) ]]>
以上是关于SQL,JSON查询-的主要内容,如果未能解决你的问题,请参考以下文章
需要 SQL 查询帮助以解析 BigQuery 表中的 JSON 数据