Ordering distinct column values by (first value of) other column in aggregate function
问题 I'm trying to order the output order of some distinct aggregated text based on the value of another column with something like: string_agg(DISTINCT sometext, ' ' ORDER BY numval) However, that results in the error: ERROR: in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list I do understand why this is, since the ordering would be "ill-defined" if the numval of two repeated values differs, with that of another lying in-between. Ideally, I would like to order them by