在我的一个包含日期和事件列的表中。
select * from event
它返回,
date event
2016-03-20 Launch
2016-03-20 delete
2016-03-20 Launch
2016-03-20 launch
2016-03-19 delete
2016-03-19 stop
我希望结果使用按日期分组
date | count(Luanch) | count(delete) | count(stop)
答案 0 :(得分:1)
select date
,count(case when event = 'Launch' then 1 end) as count_Launch
,count(case when event = 'delete' then 1 end) as count_delete
,count(case when event = 'stop' then 1 end) as count_stop
from event
group by date
;
date | count_Launch | count_delete | count_stop
------------+--------------+--------------+-------------
2016-03-19 | 0 | 1 | 1
2016-03-20 | 2 | 1 | 0