hql的一些经典案例

数据插入

  • insert into table student partition(month=‘201709’)
    values(1,‘wangwu’); insert overwrite table student
    partition(month=‘201708’)

  • select id, name from student where month=‘201709’;
    数据导出
    Insert 导出

  • insert overwrite local directory ‘/opt/module/datas/export/student’
    select * from student;
    格式化导出
    -insert overwrite local directory ‘/opt/module/datas/export/student1’ ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’ select * from student;

  • CONCAT(string A/col, string B/col…):返回输入字符串连接后的结果,支持任意个输入字符串;

  • CONCAT_WS(separator, str1, str2,…):它是一个特殊形式的

  • CONCAT()。第一个参数剩余参数间的分隔符。分隔符可以是与剩余参数一样的字符串。如果分隔符是 NULL,返回值也将为
    NULL。这个函数会跳过分隔符参数后的任何 NULL 和空字符串。分隔符将被加到被连接的字符串之间;

  • COLLECT_SET(col):函数只接受基本数据类型,它的主要作用是将某字段的值进行去重汇总,产生 array 类型字段。

collect_set 列转行
select 
concat (constellation,',', blood_type) constellation_blood_type,name 
from person_info; t1

孙悟空	白羊座	A
大海	射手座	A
宋宋	白羊座	B
猪八戒	白羊座	A
凤姐	射手座	A

射手座,A 大海
射手座,A 凤姐            
白羊座,A 孙悟空
白羊座,A 猪八戒
白羊座,B 宋宋

射手座,A 大海|凤姐
白羊座,A 孙悟空|猪八戒
白羊座,B 宋宋

select collect_set(constellation) from  person_info;

select 
t1.constellation_blood_type,
concat_ws('|',collect_set(t1.name))name
from(select 
concat (constellation,",", blood_type) constellation_blood_type,name 
from person_info) t1
group by  constellation_blood_type;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值