Hive中常见的SQL函数
显示HOST地址
字符串连接函数
1)concat()函数 将多个字符串用特定符号链接成一个字符串
concat(constellation, ",", blood_type,",",字段1,",",字段2,",",字段3)
select concat(constellation, ",", blood_type, ":", name) from person_info;
2)concat_ws()函数 将多个字符串用特定符号链接成一个字符串
select concat_ws(",", blood_type, constellation, name) from person_info;
3) collect_set()函数 将多个字符串用特定符号链接成一个字符串且去除重复元素。
select collect_set(constellation) from person_info;
显示本地时间戳函数
select unix_timestamp();
select current_timestamp;
字符串替换函数
将指定字符串替换成另一个字符串
将指定字符串重复指定次数
select repeat('A',3);
左补足字符串
select lpad('A',5,'B'); ==> BBBBA
右补足字符串
select rpad('A',5,'B'); ==> ABBBB
时间函数
select to_date('2019-08-10 15:22:33'); ==> 2019-08-10
时间格式化处理
select date_format('2017-01-16 09:55:54', 'yyyy-MM-dd');
select date_add('2019-11-10', 7);
select last_day('2019-11-16 09:55:54');
查看字符串长度
select length("Ab cd");
返回最大值
select greatest('5','4','1',null);
生成0到1随机数
select rand()+1;
字段分割
select split('andy','n');
开窗函数
领取专属 10元无门槛券
私享最新 技术干货