【发布时间】:2020-06-29 02:15:04
【问题描述】:
我有一个简单的问题。
我需要用日期和时间计算多个表中的所有记录,并将所有记录加到一个最终表中。
所以每个选项卡的查询是这样的
select timestamp_trunc(timestamp,day) 日期,timestamp_trunc(timestamp,hour) 小时,count(*) from table_1
select timestamp_trunc(timestamp,day) 日期,timestamp_trunc(timestamp,hour) 小时,count(*) from table_2
select timestamp_trunc(timestamp,day) 日期,timestamp_trunc(timestamp,hour) 小时,count(*) from table_3
以此类推
我想将这些表中显示每天和每小时的总记录数的所有结果结合起来。
预期的结果会是这样的
日期、小时、表一的记录数、表二的记录数、表三的记录数…………
对此最优化的 SQL 查询是什么?
【问题讨论】:
标签: sql google-bigquery