Oracle
 sql >> Datenbank >  >> RDS >> Oracle

Verkettete Werte in SQL-Abfrage anzeigen

Sie können die Liste LISTAGG verwenden Funktion mit DECODE :

SELECT NAME, NO, 
       LISTAGG(DECODE(RODZ_ST,'JEW',IDENT_ST,NULL), ',') WITHIN GROUP (ORDER BY t.ID DESC, RODZ_ST) AS JEWS,
       LISTAGG(DECODE(RODZ_ST,'DZE',IDENT_ST,NULL), ',') WITHIN GROUP (ORDER BY t.ID , RODZ_ST) AS DZE,
       LISTAGG(DECODE(RODZ_ST,'OBR',IDENT_ST,NULL), ',') WITHIN GROUP (ORDER BY t.ID , RODZ_ST) AS OBR
  FROM ORDERS o
   LEFT JOIN TYPES t ON t.ID_PR = o.ID_ZM
  GROUP BY NAME, NO;

SQL-Fiddle-Demo