数据插入
-
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;