Home > Software engineering >  Engineer names who work under the same project
Engineer names who work under the same project

Time:03-20

I tried to display list of engineer names who work under the same project. Basically the first column or cell should have multiple EngineerName separated by , or spaces. In the second column is the ProjectID that is common between them. So the output should look like multiple rows of EngineerName lists and their common ProjectID is the second column.

I used this code and it only displayed single names for each project. Is there a way to display multiple names in one cell ?

SELECT e."EngineerName", w."ProjectID"
FROM public."Works_On" as w INNER JOIN public."Engineer" as e
ON w."EngineerID" = e."EngineerID"
GROUP BY e."EngineerName", w."ProjectID"

CodePudding user response:

Try this, though have not tested:

SELECT w.ProjectID, 
       string_agg(e.EngineerName,',')
FROM public.Works_On as w 
INNER JOIN public.Engineer as e
ON w.EngineerID" = e.EngineerID
GROUP BY w.ProjectID
  • Related