Dailycode.info

Short solution for short problems

Oracle: Concatinate columns in a group by function

I wanted to concatinate information of a column into a ; seperated column in a group by.

eg

Projectmanagerdepartmentcustomer
1MarkABDO
2PietBBDO
3StevenAMicrosoft
I want to count the number of project for each customer and see which managers and departments there are.

With a LISTAGG function this works

SELECT

count(Project) as nr, LISTAGG(manager, ' ') WITHIN GROUP (order by manager) as managers 

FROM table 

GROUP BY customer

ORDER BY customer


result will be

2            Mark;Piet            BDO

1            Steven                Microsoft