Hive Join——基于多种条件

Hive Join - based on multiple conditions

在我的 table 之一中,其中包含日期和事件列。

select * from event

它returns,

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)
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