Name age gender
competition1 3 0
competition1 3 1
competition1 2 0
competition1 2 1
competition2 3 0
competition2 3 1
competition3 1 0
我想查询在下表中转换的该表。
Name Array of ages Array of gender
'competition1', {'3','2'} {'0','1'}
'competition2', {'3'} {'0','1'}
'competition3', {'1'} {'0'}
You can aggregate by
name
, and usearray_agg(distinct ...)
to generate arrays without duplicates. Note that you can also order the values in the arrays as needed:您可以使用array_agg