Use
GROUP BY
e a função agregada string_agg()
:SELECT nummer
,string_agg(vorname, E'\n') AS vorname
,string_agg(name, E'\n') AS name
,cash
FROM mytable
GROUP BY nummer, cash
ORDER BY nummer, cash;
Eu adicionei
cash
para o GROUP BY
para chegar ao valor original e proteger contra o caso em que seria diferente para o mesmo nummer
. Quanto ao seu comentário:
SELECT nummer
,string_agg(vorname, E'\n') AS vorname
,string_agg(name, E'\n') AS name
,cash
FROM (
SELECT DISTINCT
nummer, vorname, name, cash
FROM mytable
) AS m
GROUP BY nummer, cash
ORDER BY nummer, cash;