我的查询如下所示
SELECT
league.country as id,
array_agg(DISTINCT row(league.id, league.name::varchar)) AS league_names,
FROM league
GROUP BY league.country
如何按照array_agg函数中的league.name::varchar排序?
答案 0 :(得分:3)
汇总接受ORDER BY
。所以你可以写:
array_agg(thecol ORDER BY someothercol)
e.g。
array_agg(
DISTINCT
row(league.id, league.name::varchar)
ORDER BY league.name
) AS league_names,