想象一下像这样跟踪棒球投手的 table ......
+------------+--------------------+-------+
| id | name | secondary_pitch |
+------------+--------------------+-------+
| 13 | Chris Sale | ['Curveball','Slider'] |
| 14 | Justin Verlander | ['Fastball','Changeup'] |
| 15 | CC Sabathia | ['Fastball','Curveball'] |
| 16 | Sonny Grey | ['Slider'] |
| 17 | Aldoris Chapman | [] |
+------------+--------------------+-------+
请注意 secondary_pitch 列有一个 JSON 值。因此,如果像查普曼这样的投手没有第二个投球,它不会返回 null,而是返回一个空的 JSON 字符串 ('[]')。
那我怎样才能知道没有副投手的投手数量呢?
我做不到...
select count(*) from pitchers where secondary_pitch is null
最佳答案
我认为你可以只使用 json_length()
:
where json_length(secondary_pitch) = 0
关于mysql - 检查 MySQL 中的 JSON 值是否为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51114731/