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 ;

上一篇:哪里找百度网盘资源➕薇


下一篇:[Fundamental of Power Electronics]-PART I-6.变换器电路-6.2 变换器简单罗列