Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Mostrar valores concatenados na consulta SQL


Você pode usar a lista LISTAGG função com 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;

Demonstração do SQL Fiddle