Hive的高级聚合函数
来源:互联网 发布:海诺网络 编辑:程序博客网 时间:2024/06/03 23:48
高级聚合
---------------
GROUPING SETS.
group by + union all
//查询每个cust的订单数
select count(*) from orders group by cid ;
select count(*) from orders group by orderno ;
//group + union all
select count(*) from orders group by cid union all select count(*) from orders group by orderno ;
//group by :指定按照哪些字段分组,
//grouping sets : 以上字段集如何组合。
select count(*) from orders group by cid,orderno grouping sets(cid,orderno,())
rollup
-------------
rollup扩展了group by,
rollup比grouping sets多了一层聚合(n + 1)。
GROUP BY a,b,c WITH ROLLUP
GROUP BY a,b,c GROUPING SETS ((a,b,c),(a,b),(a),())
select cid,orderno,count(*) GROUP BY cid,orderno GROUPING SETS ((cid,orderno),(cid),())
cube
-------------
扩展了grouping sets,做了各种条件的组合,不做排序。
等价于
GROUP BY a,b,c GROUPING SETS ((a,b,c),(a,b),(b,c),(a,c),(a),(b),(c),())
聚合条件
-------------
having,用于在组内过滤。
//使用having
select cid , max(price) mx from orders group by cid having mx > 100.1 ;
//嵌套子查询
select t.cid , t.mx from (select cid , max(price) mx from orders group by cid) t where t.mx > 100.1 ;
---------------
GROUPING SETS.
group by + union all
//查询每个cust的订单数
select count(*) from orders group by cid ;
select count(*) from orders group by orderno ;
//group + union all
select count(*) from orders group by cid union all select count(*) from orders group by orderno ;
//group by :指定按照哪些字段分组,
//grouping sets : 以上字段集如何组合。
select count(*) from orders group by cid,orderno grouping sets(cid,orderno,())
rollup
-------------
rollup扩展了group by,
rollup比grouping sets多了一层聚合(n + 1)。
GROUP BY a,b,c WITH ROLLUP
GROUP BY a,b,c GROUPING SETS ((a,b,c),(a,b),(a),())
select cid,orderno,count(*) GROUP BY cid,orderno GROUPING SETS ((cid,orderno),(cid),())
cube
-------------
扩展了grouping sets,做了各种条件的组合,不做排序。
等价于
GROUP BY a,b,c GROUPING SETS ((a,b,c),(a,b),(b,c),(a,c),(a),(b),(c),())
聚合条件
-------------
having,用于在组内过滤。
//使用having
select cid , max(price) mx from orders group by cid having mx > 100.1 ;
//嵌套子查询
select t.cid , t.mx from (select cid , max(price) mx from orders group by cid) t where t.mx > 100.1 ;
阅读全文
0 0
- Hive的高级聚合函数
- Hive的聚合函数
- Hive内置聚合函数
- 高级聚合函数-CUBE
- 窗口函数之聚合函数的高级用法(一)
- Hive 函数高级编程
- Hive高级函数
- Hive聚合函数及采样函数详解
- Hive聚合函数及采样函数详解
- Hive聚合函数和表生成函数
- hive 新增的聚合功能
- Hive学习之内置聚合函数
- Hive学习之自定义聚合函数
- Hive通用型自定义聚合函数(UDAF)
- Hive通用型自定义聚合函数(UDAF)
- Hive自定义UDF和聚合函数UDAF
- Hive自定义UDF和聚合函数UDAF
- Hive用户自定义聚合函数(UDAF)
- opencv中头文件详解
- C语言结构体数组同时赋值的另类用法
- HDU 6154 CaoHaha's staff
- python mysql 模糊查询
- Serializable接口
- Hive的高级聚合函数
- Cordova开发环境搭建
- 科大讯飞手写识别
- 这是一篇用测试MetaAPI的测试内容2
- 树-堆结构练习——合并果子之哈夫曼树(优先队列)
- 膜法师【NOIP提高组模拟A组8.15】
- hdu 6143 Killer Names(组合计数)(DP)
- MyBatis:系列讲解
- 22、数据压缩-霍夫曼编码