0

I have a very simple query:

select date,route,employee
from information
where date=Trunc(Sysdate)

however, since for some routes, there are more than 2 employees are assigned, so the query will return two rows

enter image description here

But I want get one route for one row, so the ideal output should be:

enter image description here

so the two names are in the same row, and combine with "|", so how can I achieve this goal in PL/SQL?

William Robertson
  • 15,273
  • 4
  • 38
  • 44
Rowling
  • 213
  • 1
  • 8
  • 20

1 Answers1

2

You can use listagg function, but you have to add Date and Route to grouping functions as well

SELECT LISTAGG(emp, ' | ')
     WITHIN GROUP (ORDER BY emp) "Emp",
       MAX(date) "Date",
       MAX(route) "Route"
FROM information
WHERE date=Trunc(Sysdate);
eduCan
  • 180
  • 1
  • 9