【问题标题】:BigQuery - duplicate rows in query with scoped aggregationBigQuery - 具有范围聚合的查询中的重复行
【发布时间】: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


    【解决方案1】:

    这是查询引擎中的一个错误......它应该只返回 1 行。我们正在内部跟踪它,希望很快就能修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-04
      • 2022-06-19
      • 2019-04-06
      • 1970-01-01
      相关资源
      最近更新 更多