hive查询

空字段赋值:NVL    给值为null的数据赋值

  select nvl(age,20) from t_preson;

时间类:

date_format:格式化时间

  select date_format(time,''yyyy-MM-dd") ;

date_add:时间和天数相加

  select date_add('2020-06-01',-5);

date_diff:两个时间相减

  select datediff('2020-06-01','2020-06-01');

case when then

  select

    id,

    sum( sex when '男' then 1 else 0),

    sum(sex when '女' then 1 else 0)

    from emp_sex group by id

if 

  select

    id,

    sum(if(sex='男',1,0)),

    sum(if(sex='女',1,0))

    from emp_sex group by id

concat :字符串拼接,列拼接,支持多列传入

  select concat('hello','-','word')

  select concat(id,num,age) from t_person

concat_ws:

  select concat('-,'hello','word','c') 

collect_set:某个字段值去重汇总,多用于json解析

explode:将一列数据拆成多列

laterral view:

  select book,category_book

  from bool

  lateral view

  explode(category) table_tmp as category_book