【问题标题】:Order string_agg over partition | BigQuery在分区上订购 string_agg |大查询
【发布时间】:2020-10-14 15:20:12
【问题描述】:

这是我的查询部分:

string_agg(product_type, "|" order by product_type desc) over(partition by email, processed_date) as full_basket

我在订购我的 string_agg 时遇到问题。问题是一个“购物篮”显示“product_a | product_b”,另一个可能显示“product_b | product_a”,这完全是一回事。

当我运行此查询时,BigQuery 给出以下错误:“[14:1] 的分析函数不支持 ORDER BY in arguments”

关于如何订购的任何想法?

【问题讨论】:

  • 我不明白,你在string_agg() 中有order by 所以顺序应该是一致的。
  • @GordonLinoff - 我现在意识到我没有提到 BigQuery 抛出的错误。添加到文本中。

标签: sql google-bigquery


【解决方案1】:

BQ Documentation 明确表示OVER 子句(也称为分析函数)与STRING_AGG() 中的其他子句不兼容。

我认为您最好的选择是在聚合之前订购。使用 CTE 组织和排序您的数据,然后在最后应用 STRING_AGG()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 2013-01-17
    相关资源
    最近更新 更多