函数说明:

grouping sets
在一个 group by 查询中,根据不同的维度组合进行聚合,等价于将不同维度的 group by 结果集进行 union all
cube
根据 group by 的维度的所有组合进行聚合
rollup
是 cube 的子集,以最左侧的维度为主,从该维度进行层级聚合。

-- grouping sets
select
order_id,
departure_date,
count(*) as cnt
from ord_test
where order_id=410341346
group by order_id,
departure_date
grouping sets (order_id,(order_id,departure_date))
; ---- 等价于以下
group by order_id
union all
group by order_id,departure_date -- cube
select
order_id,
departure_date,
count(*) as cnt
from ord_test
where order_id=410341346
group by order_id,
departure_date
with cube
; ---- 等价于以下
select count(*) as cnt from ord_test where order_id=410341346
union all
group by order_id
union all
group by departure_date
union all
group by order_id,departure_date -- rollup
select
order_id,
departure_date,
count(*) as cnt
from ord_test
where order_id=410341346
group by order_id,
departure_date
with rollup
; ---- 等价于以下
select count(*) as cnt from ord_test where order_id=410341346
union all
group by order_id
union all
group by order_id,departure_date

结果:grouping_sets, cube, rollup

hive grouping sets 等聚合函数的更多相关文章

  1. hive grouping sets 实现原理

    先下结论: 看了hive 1.1.0 grouping sets 实现(从源码及执行计划都可以看出与kylin实现不一样),(前提是可累加,如sum函数)他并没有像kylin一样先按照group by ...

  2. 9.hive聚合函数,高级聚合,采样数据

    本文主要使用实例对Hive内建的一些聚合函数.分析函数以及采样函数进行比较详细的讲解. 一.基本聚合函数 数据聚合是按照特定条件将数据整合并表达出来,以总结出更多的组信息.Hive包含内建的一些基本聚 ...

  3. 解析数仓OLAP函数:ROLLUP、CUBE、GROUPING SETS

    摘要:GaussDB(DWS) ROLLUP,CUBE,GROUPING SETS等OLAP函数的原理解析. 本文分享自华为云社区<GaussDB(DWS) OLAP函数浅析>,作者: D ...

  4. Hive学习之自己定义聚合函数

    Hive支持用户自己定义聚合函数(UDAF),这样的类型的函数提供了更加强大的数据处理功能. Hive支持两种类型的UDAF:简单型和通用型.正如名称所暗示的,简单型UDAF的实现很easy,但因为使 ...

  5. SQL Server里Grouping Sets的威力

    在SQL Server里,你有没有想进行跨越多个列/纬度的聚集操作,不使用SSAS许可(SQL Server分析服务).我不是说在生产里使用开发版,也不是说安装盗版SQL Server. 不可能的任务 ...

  6. SQL Server里Grouping Sets的威力【转】

    在SQL Server里,你有没有想进行跨越多个列/纬度的聚集操作,不使用SSAS许可(SQL Server分析服务).我不是说在生产里使用开发版,也不是说安装盗版SQL Server. 不可能的任务 ...

  7. Hive高阶聚合函数 GROUPING SETS、Cube、Rollup

    -- GROUPING SETS作为GROUP BY的子句,允许开发人员在GROUP BY语句后面指定多个统计选项,可以简单理解为多条group by语句通过union all把查询结果聚合起来结合起 ...

  8. Hive高级聚合GROUPING SETS,ROLLUP以及CUBE

    scala> import org.apache.spark.sql.hive.HiveContextimport org.apache.spark.sql.hive.HiveContext s ...

  9. Hive函数:GROUPING SETS,GROUPING__ID,CUBE,ROLLUP

    参考:lxw大数据田地:http://lxw1234.com/archives/2015/04/193.htm 数据准备: CREATE EXTERNAL TABLE test_data ( mont ...

随机推荐

  1. yii2.0 如何按需加载并管理CSS样式及JS脚本

    链接:http://www.yiichina.com/tutorial/399 (注:以下为Yii2.0高级应用测试) Yii2.0对于CSS/JS 管理,使用AssetBundle资源包类. 视图如 ...

  2. inotify+rsync安装配置

    环境 系统 IP地址 主服务器 CentOS7.4 192.168.1.1 备份服务器 CentOS7.4 192.168.1.2 一.备份服务器 安装rsync(备) wget https://rs ...

  3. Expedition---poj2431(优先队列-堆的实现)

    题目链接:http://poj.org/problem?id=2431 题意:一辆卡车需要行驶 L 距离,车上油的含量为 P,在行驶的过程中有 n 个加油站 每个加油站到终点的距离是ai,每个加油站最 ...

  4. C++ Design Pattern: What is a Design Pattern?

    Q: What is a Design Pattern? A: Design Patterns represent solutions to problems what arise when deve ...

  5. 2014年百度之星程序设计大赛 - 资格赛 1001 Energy Conversion

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/sr19930829/article/details/26003661 Energy Conversi ...

  6. DBA-常用到的动态视图分析语句

    --语句1:获取前20逻辑读取次数或逻辑写入次数或CPU 时间 ), ((CASE qs.statement_end_offset THEN DATALENGTH(qt.TEXT) ELSE qs.s ...

  7. ftp文件上传和下载

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  8. 异常来自 HRESULT:0x80070057 (E_INVALIDARG)

    莫名其妙的编译总会报错 异常来自 HRESULT:0x80070057 (E_INVALIDARG) 未能加载程序集....... 几次删除引用然后重新引用程序集还是报错 奔溃中.... 网上搜索还真 ...

  9. ELK日志分析工具

    一.ELK介绍 1.1 elasticsearch 1.1.1 elasticsearch介绍 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎 ...

  10. Xcel 测试版使用手册

    基于无任何文笔可言,所以直接上使用方法吧. 1.引用dll,如何引用dll请谷歌. 2.使用 //实例化对象 LT.XMLExcel.XlsxOption xOption = new LT.XMLEx ...