Ich habe die folgende TabelleSQL LISTAGG für verschiedene Arten von Werten
name type value
a mobile 123456
a home tel 456789
a Office addr add1
a home addr add2
b mobile 456456
b home tel 123123
b Office addr add3
b home addr add4
ich eine SQL-Tabelle wie diese
name phone address
a 123456; 456789 add1; add2
b 456456; 123123 add3; add4
machen wollen habe ich versucht, diese SQL:
SELECT name,
LISTAGG(t.CONTACT_INFO,';')
WITHIN GROUP (ORDER BY type) AS phone where type in ('mobile', 'home tel'),
LISTAGG(t.CONTACT_INFO,';')
WITHIN GROUP (ORDER BY type) AS address where type in ('Office addr', 'home addr')
FROM table t
GROUP BY name
Und es funktioniert nicht. Ich weiß, weil die WHERE-Klausel nicht da ist, wo sie sein muss. Aber wo kann ich die Einschränkungen einfügen? Wenn ich es wie
SELECT name,
LISTAGG(t.CONTACT_INFO,';')
WITHIN GROUP (ORDER BY type) AS phone,
LISTAGG(t.CONTACT_INFO,';')
WITHIN GROUP (ORDER BY type) AS address
FROM table t
GROUP BY name
tun würde es aussehen
name phone address
a 123456; 456789;add1; add2 123456; 456789;add1; add2
b 456456; 123123;add3; add4 456456; 123123;add3; add4