我有一张表:
ConnectDate ErrorCode 2015-01-01 NULL 2015-01-01 A 2015-01-01 A 2015-01-01 B 2015-01-02 B
在 MySQL 上,如何按天计算每个ErrorCode
的数量:
Date ErrorA ErrorB 2015-01-01 2 1 2015-01-02 0 1
答案 0 :(得分:2)
您将使用条件聚合:
select connectdate, sum(errorcode = 'A') as ErrorA, sum(errorcode = 'B') as ErrorB
from table t
group by connectdate;