victorzhzh 2019-12-03
(1)if函数:if(条件表达式,结果1,结果2)
hive> select if(1=2,100,200) from lxw_dual; 200 hive> select if(1=1,100,200) from lxw_dual; 100
(2)coalesce函数:返回参数中的第一个非空值;如果所有值都为null,那么返回null
hive> select COALESCE(null,‘100‘,‘50′) from lxw_dual; 100
(3)case when函数:
hive> Select case 100 when 50 then ‘tom‘ when 100 then ‘mary‘ else ‘tim‘ end from lxw_dual; mary hive> Select case 200 when 50 then ‘tom‘ when 100 then ‘mary‘ else ‘tim‘ end from lxw_dual; tim
hive> select case when 1=2 then ‘tom‘ when 2=2 then ‘mary‘ else ‘tim‘ end from lxw_dual; mary hive> select case when 1=1 then ‘tom‘ when 2=2 then ‘mary‘ else ‘tim‘ end from lxw_dual; tom