我尝试为每天的用户构建图表,每天确认用户总数和待处理用户总数,我需要以下数据:
date | confirmed | pending
2010-01-05 | 5 | 2
2010-01-06 | 10 | 3
以下是表格的结构:
user_id
username
confirm enum(0,1)
date date
答案 0 :(得分:1)
SELECT Date, SUM(CASE Confirm WHEN 1 THEN 1 ELSE 0 END) Confirmed,
SUM(CASE Confirm WHEN 0 THEN 1 ELSE 0 END) Pending,
FROM Table
GROUP BY Date