数据透视表:从一列获取数据

时间:2010-09-22 07:01:12

标签: mysql count pivot-table

让我的表格如下:

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

表示,计算状态栏中包含的接受或拒绝金额。我该怎么做?

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

更新**并正常工作