語法: COALESCE(T v1, T v2,…)app
返回值: Tcode
說明: 返回參數中的第一個非空值;若是全部值都爲NULL,那麼返回NULLxml
示例:ci
hive> select COALESCE(null,'100','50′) from lxw_dual;it
100io
實際應用table
代碼class
insert overwrite table user_profile_db.t_population_before_apply_city partition(datepartition='${day_01}') select a.cid, COALESCE(b.city_name,a.population_apply_city) as city_name from (select * from user_profile_db.t_population_apply_city where datepartition='${day_01}' )a left join (select cid, city_name from (select *, ROW_NUMBER() over(partition by cid order by create_date asc) as rank from (select a.rank_apply, b.* from ( select * from user_profile_db.t_population_apply_city where datepartition='${day_01}' ) a inner join ( select * from user_profile_db.t_population_cnt_before_after_apply_tmp where datepartition='${day_01}' ) b on a.cid=b.cid ) a ) b where rank=rank_apply-1 and datediff(cnt_apply_time,create_date)<30 and datediff(cnt_apply_time,create_date)>=0 )b on a.cid=b.cid ;
若是b.city_name is null 則取a.population_apply_city的值 能夠理解爲至關於case when模式date