首页 > 其他 > 详细

hive查询

时间:2020-06-15 22:27:45      阅读:48      评论:0      收藏:0      [点我收藏+]

空字段赋值: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

 

hive查询

原文:https://www.cnblogs.com/saber-xi/p/13137740.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!