Oracle
 sql >> Database >  >> RDS >> Oracle

Come combinare più righe in una singola riga, oracle

Try this ...



'SELECT distinct
P.CODE AS "projectNumber", 
P.NAME AS "projectName", 
P.START_DATE AS "startDate", 
P.END_DATE AS "endDate",

LISTAGG((VP.firstName || ' ' || VP.lastName), ' ') WITHIN GROUP (order by rownum) AS VP,
TRIM (SRPM.firstName || ' ' || SRPM.lastName) AS "srpm",
TRIM (PM.firstName || ' ' || PM.lastName) AS "pm",
TRIM (SUP.firstName || ' ' || SUP.lastName) AS "sup",
TRIM (PE.firstName || ' ' || PE.lastName) AS "pe"
FROM DA.ROJECT_TABLE P
LEFT JOIN BA.teams_v VP on (P.CODE=VP.projectnumber and VP.code not in ('30', '85', 'ZZ') and VP.employoeenumber is not null and VP.status='A' and VP.projectrolename in ('Sr. Vice President, CFO','Senior Vice President','Vice President','President','Sr. Vice President','Vice President of Operations','Vice President', 'Chief Estimator','Vice President, Senior Project Manager','Vice President of Preconstruction and Estimating','Executive Vice President','Vice President, Sr. Project Manager'))
LEFT JOIN BA.teams_v SRPM on (P.CODE=SRPM.projectnumber and SRPM.code not in ('30', '85', 'ZZ') and SRPM.employoeenumber is not null and SRPM.status='A' and SRPM.projectrolename in ('Vice President/Sr. Project Manager','Senior Project Manager','Vice President, Senior Project Manager','Vice President, Sr. Project Manager'))
LEFT JOIN BA.teams_v PM on (P.CODE=PM.projectnumber and PM.code not in ('30', '85', 'ZZ') and PM.employoeenumber is not null and PM.status='A' and PM.projectrolename in ('Project Manager','Assistant Project Manager','Manager, Project Accounting','Asst. Project Manager'))
LEFT JOIN BA.teams_v SUP on (P.CODE=SUP.projectnumber and SUP.code not in ('30', '85', 'ZZ') and SUP.employoeenumber is not null and SUP.status='A' and SUP.projectrolename in ('Assistant Superintendent','CMatt - Superintendent','General Superintendent'))
LEFT JOIN BA.teams_v PE on (P.CODE=PE.projectnumber and PE.code not in  ('30', '85', 'ZZ') and PE.employoeenumber is not null and PE.status='A' and PE.projectrolename in ('Senior Project Engineer','Sr. Project Engineer','Intern Asst. Project Engineer','Assistant Project Engineer','Intern Project Engineer','Project Engineer'))'