mysql json存null字符串怎么查?

mysql json存null字符串怎么查?

如图, sport 是 json 字段,要把sport为 null 字符串这一行查出来

无效查询

select * from tb where sport = 'null'
select * from tb where sport is null
SELECT * FROM tb WHERE sport = '"null"'

MySQL5.7 的 json 字符串

能存 json字符串, null字符串, null值, 数字
但是不能存其它 纯字符串

本作品采用《CC 协议》,转载必须注明作者和本文链接
reading
白小二
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 10

用双引号包起来

select * from tb where json_str = '"null"'
2年前 评论
白小二 (楼主) 2年前
Rache1 (作者) 2年前
seaChild

select * from 24ke_work_task where json =json_array() or json is null 如果是json 里面的字段 要这样 json->'$.field' = json_array()

file

2年前 评论
白小二 (楼主) 2年前
select * from tb where JSON_CONTAINS(`sport`, 'null');
select * from tb where JSON_CONTAINS(`sport`, 'null', '$');
2年前 评论

SELECT * FROM tb WHERE JSON_TYPE(sport) = 'NULL'

2年前 评论

select * from tb where JSON_TYPE(sport) is NULL

2年前 评论

select * from tb where JSON_DEPTH(sport) = 1

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!