Oracle
 SQL >> Datenbank >  >> RDS >> Oracle

Distinkte Werte mit LISTAGG in Oracle 12C

First compute distinct values, then aggregate them with LISTAGG:

WITH test(id, col) AS (
  SELECT 1, 'x' FROM dual UNION ALL
  SELECT 2, 'w' FROM dual UNION ALL
  SELECT 2, 'w' FROM dual
),
temp AS (
  SELECT DISTINCT id, col FROM test
)
SELECT id,
  LISTAGG(col, ';') WITHIN GROUP (ORDER BY col) AS result
FROM temp
GROUP BY id;