sql - 通过 BigQuery 与 Teradata 中的分组集进行分组
问题描述
BigQuery 是否具有与group by GROUPING SETS
Teradata 中相同的功能?
例如在 Teradata 中,我们可以使用类似的东西
group by GROUPING SETS ( (1,2,3,4,5,6 ), (1,2,4,5,6 ))
BigQuery 有可能吗?
解决方案
当您需要汇总统计信息(例如 sum、min、max 等)时,可以从上述示例之一中详细说明另一种选择
with table as (select 'au' dim1, 'samsung' dim2, 'browser1' dim3 , 100 clk, 10000 e
union all
select 'ind' c, 'iphone' d, 'browser2' b , 1000 clk, 10000 e
union all
select 'ind' c, 'samsung' d, 'browser2' b , 10 clk, 1 e)
select
dim1
,dim2
,dim3
,max(clk)clk
,max(e) e
from
(SELECT
dim1
,dim2
,dim3
,sum(clk) over (partition by dim1,dim2,dim3) clk
,sum(e) over (partition by dim1,dim2,dim3) e
FROM table,
UNNEST ([dim1, 'ALL']) AS dim1,
UNNEST ([dim2, 'ALL']) AS dim2,
UNNEST ([dim3, 'ALL']) AS dim3
)
GROUP BY dim1,dim2,dim3
推荐阅读
- javascript - 当另一个模态模态在其中打开时模糊背景模态
- java - 如何在 Drools 7 中实现 Drools 5 示例
- android - 布局设计中缺少属性 - Android Studio
- javascript - 我应该如何修改 PHP 和 Javascript 文件以使复选框是强制性的?
- python - Thead.join() 只有在所有线程都完成后才帮助打印字符串
- regex - 自定义显着降价插件仅解析匹配的正则表达式的第一个实例
- python - 尽管列出了绝对路径,但在 Ubuntu 中找不到文件错误
- google-sheets - 对 ID 的数字字母组合执行 COUNTIF 的区分大小写的公式
- javascript - 问题迭代节点列表
- android - 在不更新 apk 的情况下从 android 中的 Internet 动态更改布局