BigQuery GROUP_CONCAT and ORDER BY

前端 未结 3 1936
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 19:14

I am currently using BigQuery and GROUP_CONCAT which works perfectly fine. However, when I try to add a ORDER BY clause to the GROUP_CONCAT statement like I would do in SQL,

3条回答
  •  -上瘾入骨i
    2020-12-10 19:36

    Standard SQL mode in BigQuery does support ORDER BY clause within some aggregate functions, including STRING_AGG, for example:

    #standardSQL
    select string_agg(t.x order by t.y) 
    from unnest([struct('a', 5), ('b', 1), ('c', 10)]) t
    

    will result in

    b,a,c

    Documentation is here: https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#using-order-by-with-aggregate-functions

提交回复
热议问题