版本要求5.7+
https://blog.csdn.net/baidu_38609744/article/details/105897825
首先是JSON_UNQUOTE函数 望文生义 就是去掉引号的功能 将原json串的引号去掉转成string类型
然后来说下JSON_EXTRACT函数
根据键查对象
SELECT JSON_EXTRACT(content_img, '
.
p
a
t
h
′
)
f
r
o
m
m
e
w
h
e
r
e
i
d
=
3
结
论
通
过
.path') from me where id = 3 结论 通过
.path′)frommewhereid=3结论通过加.键名取出对象的value
数组类型的查询
example1:
select JSON_EXTRACT(content_img -> '$[0]', '$.path' ) from me where id = 1
example2:
select JSON_EXTRACT(content_img -> '$[1]', '$.path' ) from me where id = 2
结论
通过箭头符号 -> 来选择数组下标 $符号加.键名选择需要的值
查询判断json是否有值,如果有进行合并在一个单元格里面
CONCAT(
( CASE WHEN (json_unquote(JSON_EXTRACT( y.s1, '$.s1_D26' )) ) > 0 THEN json_unquote(JSON_EXTRACT( y.s1, '$.s1_D26' )) ELSE '' END),
( CASE WHEN ( json_unquote(JSON_EXTRACT( y.s1, '$.s1_D27' )) ) > 0 THEN json_unquote(JSON_EXTRACT( y.s1, '$.s1_D27' )) ELSE '' END ),
( CASE WHEN ( json_unquote(JSON_EXTRACT( y.s1, '$.s1_D28' )) ) > 0 THEN json_unquote(JSON_EXTRACT( y.s1, '$.s1_D28' )) ELSE '' END )
) AS s1_D25