如何合并大量表的汇总结果?

时间:2019-04-27 17:13:49

标签: google-bigquery

我有很多表,它们的名字如下:

datasetW01.W01_*datasetW02.W02_*〜100

如何优化以下SQL?

#standardSQL
WITH result1 AS (
  SELECT Col1, COUNT(Col1) AS count
  FROM `dataset.W01_*`
  GROUP BY Col1
), result2 AS (
  SELECT Col1, COUNT(Col1) AS count
  FROM `dataset.W02_*`
  GROUP BY Col1
)
SELECT col1, GREATEST(IFNULL(t1.count, t2.count), IFNULL(t2.count, t1.count)) count
FROM result1 t1 
FULL OUTER JOIN result2 t2
USING (col1)
ORDER BY count DESC

对于数据集W01.W01_ ,数据集W02.W02 _ ,数据集W03.W03_ ,数据集W04.W04 _ ,数据集W05.W05_ *等,只需一个查询?

0 个答案:

没有答案