0


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 &#

标签: java 数据库 mysql

本文转载自: https://blog.csdn.net/u010438126/article/details/126266026
版权归原作者 奋进的码哥 所有, 如有侵权,请联系我们删除。

“hive中case when的两种使用方法”的评论:

还没有评论