[cloudera@quickstart ~]$ cat > emp.txt
eno name sal g dno
101,AAAAA,1000.00,m,11
102,BBBBB,2000.00,m,12
103,CCCCC,3000.00,f,13
104,DDDDD,4000.00,f,14
105,EEEEE,5000.00,m,15
106,FFFFF,6000.00,f,16
107,GGGGG,7000.00,m,17
108,HHHHH,8000.00,m,18
109,xxxxx,1000.00,f,11
110,yyyyy,2000.00,f,18
111,zzzzz,2000.00,f,15
hive>create table empdata (eno int,name string,sal double,gender string,dno int)
row format delimited fields terminated by '.';
hive>load data local inpath 'emp.txt' into table empdata;
hive> select col1,col2...,case colname
> when val1 then statement
> when val2 then statement
> when val3 then statement
> else statement
> end
> from tablename;
hive> select name,case dno
> when 11 then 'marketing'
> when 12 then 'finance'
> when 13 then 'hr'
> when 14 then 'abc'
> when 15 then 'xyz'
> when 16 then 'training'
> else 'select Proper choice'
> end
> from empdata;
case:
hive> select dno,case dno
> when 11 then 'maeketing'
> when 12 then 'hr'
> when 13 then 'finance'
> else 'others'
> end
> from empdata;
hive> select name,case gender
> when 'm' then 'male'
> when 'f' then 'female'
> else gender
> end
> from empdata
eno name sal g dno
101,AAAAA,1000.00,m,11
102,BBBBB,2000.00,m,12
103,CCCCC,3000.00,f,13
104,DDDDD,4000.00,f,14
105,EEEEE,5000.00,m,15
106,FFFFF,6000.00,f,16
107,GGGGG,7000.00,m,17
108,HHHHH,8000.00,m,18
109,xxxxx,1000.00,f,11
110,yyyyy,2000.00,f,18
111,zzzzz,2000.00,f,15
hive>create table empdata (eno int,name string,sal double,gender string,dno int)
row format delimited fields terminated by '.';
hive>load data local inpath 'emp.txt' into table empdata;
hive> select col1,col2...,case colname
> when val1 then statement
> when val2 then statement
> when val3 then statement
> else statement
> end
> from tablename;
hive> select name,case dno
> when 11 then 'marketing'
> when 12 then 'finance'
> when 13 then 'hr'
> when 14 then 'abc'
> when 15 then 'xyz'
> when 16 then 'training'
> else 'select Proper choice'
> end
> from empdata;
case:
hive> select dno,case dno
> when 11 then 'maeketing'
> when 12 then 'hr'
> when 13 then 'finance'
> else 'others'
> end
> from empdata;
hive> select name,case gender
> when 'm' then 'male'
> when 'f' then 'female'
> else gender
> end
> from empdata
No comments:
Post a Comment