我需要将所有可能等于“0”的结果替换为空值。最好的选择是什么?在这种情况下,请使用case语句或replace命令:
SELECT name, COUNT(IF(stat='open',1, NULL)) 'open',
COUNT(IF(stat='close',1, NULL)) 'close',
COUNT(IF(stat='all',1, NULL)) 'all',
COUNT(IF(stat='reopen',1, NULL)) 'reopen',
COUNT(IF(stat='finish',1, NULL)) 'finish'
FROM dashboard group by name order by name = 'Party' desc
+----------+------+-------+-----+--------+--------+
| name | open | close | all | reopen | finish |
+----------+------+-------+-----+--------+--------+
| Party | 21 | 0 | 0 | 0 | 0 |
+----------+------+-------+-----+--------+--------+
2条答案
按热度按时间amrnrhlw1#
你可以用
NULLIF()
功能。uqzxnwby2#
一种方法使用
NULLIF()
:其他用途
CASE
: