函数(hive)
2020-08-21 11:58
127 查看
1.NVL(空字段赋值)
nvl函数,当查询的结果为null时默认值为后面的参数,100
select nvl(salary,100) from emp;
2.case
统计emp表中的,每一个部门的男女数量
select dept_id, count(*) total, --sum(case sex when 'man' then 1 when 'renyao' then 0.5 else 0 end) male, sum(case sex when 'man' then 1 else 0 end) male, sum(case sex when 'woman' then 1 else 0 end) female, from emp group by dept_id;
3.行转列
统计血型相同、星座相同的人数,并把血型和星座拼接,把人名也进行拼接
select constellation,--星座 blood_type,--血型 sum(*) from person group by constellation,blood_type;
//collect_list不去重,collect_set去重
//concat连接两个字段
select --拼接血型和星座 concat(constellation,blood_type) cb --把查询到的人名放入collect_list里,然后使用concat_ws进行拼接 concat_ws("|",collect_list(name)) rentou from person group by constellation,blood_type;
4.行转列
gaoyuanyuan0 87,98,97,60
gaoyuanyuan1 88,98,94,60
gaoyuanyuan2 89,98,97,60,100
create table if not exists arr2( name string, score array<string> )row format delimited fields terminated by "\t" collection items terminated by "," ;
select name,scoe[2] from arr2;
explode展开:
select explode(score) from arr2;
相关文章推荐
- hive 开窗函数的使用
- hive-2 自定义函数UDF、UDAF、UDTF介绍及区别
- 面试题hive自定义函数输入输出特性
- Hive自定义函数
- hive2.0函数大全
- Hive函数大全
- hive instr 函数
- hive 学习系列 hive 常用数据清洗函数
- hive----自定义UDF 函数-----时间格式化以及取出双引号的代码
- Hive LATERAL VIEW 函数
- hive 部署UDF函数
- Hive-函数大全1
- Hive 中的自定义函数(udf,udtf,udaf)
- Apache Hive常用函数举例
- Hive的常用函数大全
- Hive函数大全
- RHive基础函数
- Hive 混合函数 UDTF UDF
- hive下UDF函数的使用
- Hive(四)窗口函数应用大全