RICH-ATONE

hive中case when的两种使用方法

如下两种的表达效果是一样

方法一:

select
tm ,
count(tm) as times
from
(
select
case
when single_times = '1' then 'one_time'
when single_times = '2' then 'two_time'
when single_times = '3' then 'three_time'
when single_times = '4' then 'four_time'
when single_times = '5' then 'five_time'
else 'more_five' end as tm
from
(select count(userid) single_times from test where dt = '2020-10-12' group by userid ) t
) t
group by tm ;

 

方法二:

select
tm ,
count(tm) as times
from
(
select
case single_times
when '1' then 'one_time'
when '2' then 'two_time'
when '3' then 'three_time'
when '4' then 'four_time'
when '5' then 'five_time'
else 'more_five' end as tm
from
(select count(userid) single_times from test where dt = '2020-10-12' group by userid ) t
) t
group by tm ;

posted on 2020-10-13 18:59  RICH-ATONE  阅读(15235)  评论(0编辑  收藏  举报

导航