Answer the question
In order to leave comments, you need to log in
How to speed up SELECT query with LISTAGG?
Hello.
There are two tables, humans and connects. Like these ones:
-- humans
id name
1001 Алексеев Алексей Алексеевич
1002 Борисов Борис Борисович
1003 Васильев Василий Васильевич
...
-- connects
id humanid type conn
2001 1001 phone 123456
2002 1001 email [email protected]
2003 1001 email [email protected]
2004 1001 email [email protected]
2005 1002 phone 234532
2006 1002 phone 232323
2007 1002 phone 212121
2008 1003 email [email protected]
2009 1003 phone 345678
2010 1003 phone 313131
id name phone
1001 Алексеев Алексей Алексеевич 123456
1002 Борисов Борис Борисович 212121,232323,234532
1003 Васильев Василий Васильевич 313131,345678
with qconnect as
(
select
humanid,
listagg(conn, ',') within group(order by conn) as phone
from connects
where
type = 'phone'
group by humanid
)
select
h.id,
h.name,
c.phone
from
humans h,
qconnect c
where h.id = c.humanid;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question