1. 程式人生 > >hive case when then 多條件

hive case when then 多條件

select substr(key,13,2),
case when birthday<'1968' then '50up'
 when birthday<'1978' then '40-50'
 when birthday<'1983' then '35-40'
 when birthday<'1988' then '30-35'
 when birthday<'1992' then '26-30'
 when birthday<'1998' then '20-25'
 else 'other' end,
count(1) 
from hiveTable 
group by substr(key,13,2), 
case when birthday<'1968' then '50up'
 when birthday<'1978' then '40-50'
 when birthday<'1983' then '35-40'
 when birthday<'1988' then '30-35'
 when birthday<'1992' then '26-30'
 when birthday<'1998' then '20-25'
 else 'other' end