【发布时间】:2014-12-04 07:22:22
【问题描述】:
我正在尝试运行一个使用 group_concat 函数和范围聚合的查询。 以下查询返回 175 行,所有行都具有相同的值。重复似乎是 cell.value 中有 175 个元素的结果
SELECT
ngram,
group_concat(cell.sample.id) within record con
FROM [publicdata:samples.trigrams]
where ngram = '! ! That'
当向上面的查询添加新列时(count 具有范围聚合),结果是一行,正如预期的那样。计数行显示值 175。
SELECT
ngram,
count(cell.value) within record cnt,
group_concat(cell.sample.id) within record con
FROM [publicdata:samples.trigrams]
where ngram = '! ! That'
似乎发生行重复是因为没有要分组的值(所有空值)。如果我将 group_concat 更改为:
group_concat(if(cell.sample.id is null,'',cell.sample.id)) within record con
然后再一次只有一行。
这是什么原因?
如果不对所有列使用 group by,如何避免这种情况(这也需要子查询,因为不可能将 group by 和作用域聚合函数结合起来)?
【问题讨论】:
标签: google-bigquery