HIVE_case when

Posted 李杰然

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HIVE_case when相关的知识,希望对你有一定的参考价值。

create table Pl(Na varchar2(15),   Sh varchar2(15),
            Mj varchar2(15),Gt int, Sa int,Jt varchar2(20));

insert into  Pl values(‘sunhongyu‘,‘yiben‘,‘jisuanji‘,3,30000,‘jishu‘);
insert into  Pl values(‘wuweilong‘,‘erben‘,‘feijisuanji‘,15,25000,‘jishu‘);
insert into  Pl values(‘sunjicheng‘,‘erben‘,‘jisuanji‘,7,55000,‘jishu‘);
insert into  Pl values(‘zhangsan‘,‘chengren‘,‘jisuanji‘,4,7000,‘houqin‘);
insert into  Pl values(‘wangliu‘,‘chengren‘,‘feijisuanji‘,8,13000,‘houqin‘);
insert into  Pl values(‘wanger‘,‘zhuanke‘,‘feijisuanji‘,4,2000,‘jishu‘);
insert into  Pl values(‘lisi‘,‘sanben‘,‘jisuanji‘,25,4000,‘xiaoshou‘);
insert into  Pl values(‘zhaowu‘,‘zhuanke‘,‘jisuanji‘,5,6000,‘jishu‘);
insert into  Pl values(‘zhengliu‘,‘zhuanke‘,‘jisuanji‘,3,3000,‘houqin‘);
insert into  Pl values(‘sabi‘,‘erben‘,‘feijisuanji‘,13,14000,‘jishu‘);
commit;




create table Sg(Sh varchar2(15),Ig int );
insert into  Sg values(‘yiben‘,5);
insert into  Sg values(‘erben‘,4);
insert into  Sg values(‘sanben‘,3);
insert into  Sg values(‘chengren‘,2);
insert into  Sg values(‘zhuanke‘,1);
commit;


create table Mi(Mj varchar2(15),Ig int );
insert into Mi values(‘jisuanji‘,3);
insert into Mi values(‘feijisuanji‘,2);
commit;


create table Gi(Gt varchar2(19),Ig int );
insert into Gi values(‘1-10‘,1);
insert into Gi values(‘10-20‘,2);
insert into Gi values(‘20-40‘,4);
commit;

create table Si(Sa varchar2(15),Ig int );
insert into Si values(‘1000-3000‘,1);
insert into Si values(‘3000-10000‘,2);
insert into Si values(‘10000-20000‘,4);
insert into Si values(‘20000-200000‘,8);
commit;

create table Jg(Jt varchar2(20),Ig int );
insert into Jg values(‘jishu‘,5);
insert into Jg values(‘xiaoshou‘,4);
insert into Jg values(‘houqin‘,3);
commit;


create table Cf as select  
max(
case when a.Sh=‘yiben‘ and a.Sh=b.Sh then
case when a.Mj=‘jisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=1 and a.Gt<=10 and d.Gt=‘1-10‘ then  
case when a.Sa>20000 and a.Sa<=200000 and e.Sa=‘20000-200000‘ then
case when a.Jt=‘jishu‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘erben‘ and a.Sh=b.Sh then
case when a.Mj=‘feijisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=10 and a.Gt<=20 and d.Gt=‘10-20‘ then  
case when a.Sa>20000 and a.Sa<=200000 and e.Sa=‘20000-200000‘ then
case when a.Jt=‘jishu‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘erben‘ and a.Sh=b.Sh then
case when a.Mj=‘jisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=1 and a.Gt<=10 and d.Gt=‘1-10‘ then  
case when a.Sa>20000 and a.Sa<=200000 and e.Sa=‘20000-200000‘ then
case when a.Jt=‘jishu‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘chengren‘ and a.Sh=b.Sh then
case when a.Mj=‘jisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=1 and a.Gt<=10 and d.Gt=‘1-10‘ then  
case when a.Sa>3000 and a.Sa<=10000 and e.Sa=‘3000-10000‘ then
case when a.Jt=‘houqin‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘chengren‘ and a.Sh=b.Sh then
case when a.Mj=‘feijisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=1 and a.Gt<=10 and d.Gt=‘1-10‘ then  
case when a.Sa>10000 and a.Sa<=20000 and e.Sa=‘10000-20000‘ then
case when a.Jt=‘houqin‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘zhuanke‘ and a.Sh=b.Sh then
case when a.Mj=‘feijisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=1 and a.Gt<=10 and d.Gt=‘1-10‘ then  
case when a.Sa>1000 and a.Sa<=3000 and e.Sa=‘1000-3000‘ then
case when a.Jt=‘jishu‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘sanben‘ and a.Sh=b.Sh then
case when a.Mj=‘jisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=20 and a.Gt<=40 and d.Gt=‘20-40‘ then  
case when a.Sa>3000 and a.Sa<=10000 and e.Sa=‘3000-10000‘ then
case when a.Jt=‘xiaoshou‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘zhuanke‘ and a.Sh=b.Sh then
case when a.Mj=‘jisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=1 and a.Gt<=10 and d.Gt=‘1-10‘ then  
case when a.Sa>=3000 and a.Sa<=10000 and e.Sa=‘3000-10000‘ then
case when a.Jt=‘jishu‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘zhuanke‘ and a.Sh=b.Sh then
case when a.Mj=‘jisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=1 and a.Gt<=10 and d.Gt=‘1-10‘ then  
case when a.Sa>=3000 and a.Sa<=10000 and e.Sa=‘3000-10000‘ then
case when a.Jt=‘houqin‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end||
case when a.Sh=‘erben‘ and a.Sh=b.Sh then
case when a.Mj=‘feijisuanji‘ and a.Mj=c.Mj then
case when a.Gt>=10 and a.Gt<=20 and d.Gt=‘10-20‘ then  
case when a.Sa>10000 and a.Sa<=20000 and e.Sa=‘10000-20000‘ then
case when a.Jt=‘jishu‘ and a.Jt=f.Jt then  
case when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>=1 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=5 then ‘e‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>5 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=10 then ‘d‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>10 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=15 then ‘c‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>15 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=20 then ‘b‘
     when b.Ig+c.Ig+d.Ig+e.Ig+f.Ig>20 and b.Ig+c.Ig+d.Ig+e.Ig+f.Ig<=25 then ‘a‘ end end end end end end
)
as "T",a.Na  from Pl a,Sg b,Mi c,Gi d,Si e,Jg f group by a.Na;

create table Rm as select Na,case when T=‘a‘ then ‘大数据,开发‘
when T=‘b‘ then ‘运维,测试‘
when T=‘c‘ then ‘网管,监控‘
when T=‘d‘ then ‘文案,修门‘
when T=‘e‘ then ‘保安,打杂‘
end as Rc from Cf;

以上是关于HIVE_case when的主要内容,如果未能解决你的问题,请参考以下文章