我有一个mysql查询:
SELECT CASE WHEN roomid = 1 THEN SUM(taxmoney) END END AS 'total1',
CASE WHEN roomid = 2 THEN SUM(taxmoney) END AS 'total2',
DATE_FORMAT(end_at,'%Y-%m-%d') AS 'date_time' FROM match_logs GROUP BY
DATE_FORMAT(end_at,'%Y-%m-%d')
这是我执行时的结果:
total1 || total2 || date_time
52040 || NULL || 2015-03-31
89803 || NULL || 2015-04-01
45250 || 4658 || 2015-04-02
我想将NULL
列中的total2
更改为0
。我该怎么办?
全部谢谢!
答案 0 :(得分:1)
将此命令用于total2:
CASE WHEN roomid = 2 THEN IFNULL(SUM(taxmoney),'0') END AS 'total2',
完整的命令:
SELECT CASE WHEN roomid = 1 THEN SUM(taxmoney) END AS 'total1',
CASE WHEN roomid = 2 THEN IFNULL(SUM(taxmoney),'0') END AS 'total2',
DATE_FORMAT(end_at,'%Y-%m-%d') AS 'date_time' FROM match_logs GROUP BY
DATE_FORMAT(end_at,'%Y-%m-%d')