在分区上排序 string_agg | 大查询

jer*_*144 3 sql google-bigquery

这是我的有问题的查询:

string_agg(product_type, "|" order by product_type desc) over(partition by email, processed_date) as full_basket
Run Code Online (Sandbox Code Playgroud)

我在订购 string_agg 时遇到问题。问题在于,一个“篮子”显示“product_a | Product_b”,另一个“篮子”可能显示“product_b | Product_a”,这是完全相同的事情。

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

关于如何订购有什么想法吗?

rte*_*nha 5

BQ 文档特别指出,OVER子句(又名分析函数)与STRING_AGG().

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