让我的表格如下:
Date Status
2010-01-02
2010-01-03 accept
2010-01-03 accept
2010-01-03 reject
2010-01-03
2010-01-04 reject
我想如果值为null,则表示接受。除此之外我想要显示结果如:
Date Accept Reject
2010-01-02 1 0
2010-01-03 3 1
2010-01-04 0 1
表示,计算状态栏中包含的接受或拒绝金额。我该怎么做?
答案 0 :(得分:0)
SELECT DATE AS DATE, SUM( IF(
STATUS = 'accept', 1, 0 ) ) AS Accept, SUM( IF(
STATUS = 'reject', 1, 0 ) ) AS Reject
FROM pivot
GROUP BY DATE
更新**并正常工作