这是我查询的结果:
这是我最后要需要的结果:
这是我的SQL:
SELECT a.SITE_PIC_NAME 板块公司,b.NEW_NUM as "新建(项目数)",b.UPDATE_NUM as "改建(项目数)",b.BIG_NUM as "扩建(项目数)",a.NEW_NOT_VALID_NUM as "新建(不合规)",a.UPDATE_NOT_VALID_NUM as "改建(不合规)",a.BIG_NOT_VALID_NUM as "扩建(不合规)" from
((SELECT SITE.SITE_PIC_NAME,NVL(NEW_NOT_VALID_NUM,0) AS NEW_NOT_VALID_NUM,NVL(UPDATE_NOT_VALID_NUM,0) AS UPDATE_NOT_VALID_NUM,
NVL(BIG_NOT_VALID_NUM,0) AS BIG_NOT_VALID_NUM FROM VLD_SITE SITE LEFT JOIN (
SELECT VVS.VLD_ENTERPRISE_ID,SUM(DECODE(PROJ_PROPERTY,'1',CASE WHEN S_VALID=1 AND H_VALID=1 AND E_VALID=1 THEN 0 ELSE 1 END,0)) AS NEW_NOT_VALID_NUM,
SUM(DECODE(PROJ_PROPERTY,'2',CASE WHEN S_VALID=1 AND H_VALID=1 AND E_VALID=1 THEN 0 ELSE 1 END,0)) AS UPDATE_NOT_VALID_NUM,
SUM(DECODE(PROJ_PROPERTY,'4',CASE WHEN S_VALID=1 AND H_VALID=1 AND E_VALID=1 THEN 0 ELSE 1 END,0)) AS BIG_NOT_VALID_NUM FROM (
SELECT DECODE(T.IS_SAFETY_E,1,DECODE(T.PROJECT_STATE,'1',DECODE(T.CURRENT_STAGE,'1',1,'2',DECODE(S_PRE.ISOK,'1',1,0),'3',CASE WHEN S_PRE.ISOK='1' AND S_DESIGN.ISOK='1' THEN 1 ELSE 0 END,'4',CASE WHEN S_PRE.ISOK='1' AND S_DESIGN.ISOK='1' AND S_RISK.ISOK='1' THEN 1 ELSE 0 END,'5',CASE WHEN S_PRE.ISOK='1' AND S_DESIGN.ISOK='1' THEN 1 ELSE 0 END),'2',CASE WHEN S_PRE.ISOK='1' AND S_DESIGN.ISOK='1' AND S_RISK.ISOK='1' AND S_CHECKED.ISOK='1' THEN 1 ELSE 0 END),1) AS S_VALID,
DECODE(T.IS_HEALTHY_E,1,DECODE(T.PROJECT_STATE,'1',DECODE(T.CURRENT_STAGE,'1',1,'2',DECODE(H_PRE.ISOK,'1',1,0),'3',CASE WHEN H_PRE.ISOK='1' AND H_DESIGN.ISOK='1' THEN 1 ELSE 0 END,'4',CASE WHEN H_PRE.ISOK='1' AND H_DESIGN.ISOK='1' THEN 1 ELSE 0 END,'5',CASE WHEN H_PRE.ISOK='1' AND H_DESIGN.ISOK='1' THEN 1 ELSE 0 END),'2',CASE WHEN H_PRE.ISOK='1' AND H_DESIGN.ISOK='1' AND H_CHECKED.ISOK='1' THEN 1 ELSE 0 END),1) AS H_VALID,
DECODE(T.IS_ENVIROMENT_E,1,DECODE(T.PROJECT_STATE,'1',DECODE(T.CURRENT_STAGE,'1',1,'2',DECODE(E_PRE.ISOK,'1',1,0),'3',CASE WHEN E_PRE.ISOK='1' THEN 1 ELSE 0 END,'4',CASE WHEN E_PRE.ISOK='1' AND E_DESIGN.ISOK='1' THEN 1 ELSE 0 END,'5',CASE WHEN E_PRE.ISOK='1' THEN 1 ELSE 0 END),'2',CASE WHEN E_PRE.ISOK='1' AND E_DESIGN.ISOK='1' AND E_CHECKED.ISOK='1' THEN 1 ELSE 0 END),1) AS E_VALID,T.VLD_SITE_ID,T.PROJ_PROPERTY FROM C_PROJ_MAIN_TB T
INNER JOIN VLD_SITE VS ON T.VLD_SITE_ID=VS.VLD_SITE_ID
LEFT JOIN C_PROJ_S_PREASSESS_TB S_PRE ON T.PROJ_ID=S_PRE.PROJ_ID
LEFT JOIN C_PROJ_S_DESIGN_TB S_DESIGN ON T.PROJ_ID=S_DESIGN.PROJ_ID
LEFT JOIN C_PROJ_S_CHECKED_TB S_CHECKED ON T.PROJ_ID=S_CHECKED.PROJ_ID
LEFT JOIN C_PROJ_ASSESS_H_TB H_PRE ON T.PROJ_ID=H_PRE.PROJ_ID
LEFT JOIN C_PROJ_DESIGN_H_TB H_DESIGN ON T.PROJ_ID=H_DESIGN.PROJ_ID
LEFT JOIN C_PROJ_CHECE_H_TB H_CHECKED ON T.PROJ_ID=H_CHECKED.PROJ_ID
LEFT JOIN C_PROJ_ASSESS_E_TB E_PRE ON T.PROJ_ID=E_PRE.PROJ_ID
LEFT JOIN C_PROJ_DESIGN_E_TB E_DESIGN ON T.PROJ_ID=E_DESIGN.PROJ_ID
LEFT JOIN C_PROJ_CHECE_E_TB E_CHECKED ON T.PROJ_ID=E_CHECKED.PROJ_ID
LEFT JOIN C_RISK_MAKE_TB S_RISK ON T.PROJ_ID=S_RISK.PROJ_ID
WHERE VS.ORG_STATUS='A' AND T.START_DATE>=TRUNC(SYSDATE,'YYYY')
AND T.START_DATE<=SYSDATE
)A
INNER JOIN V_VLD_SITE_ENTERPRISE VVS ON A.VLD_SITE_ID =
VVS.VLD_SITE_ID
GROUP BY VVS.VLD_ENTERPRISE_ID
) B ON SITE.VLD_SITE_ID=B.VLD_ENTERPRISE_ID
WHERE SITE.VLD_ENTITY_TYPE_ID = 20
AND SITE.ORG_STATUS = 'A'
AND SITE.RENDER_ORDER < 9999
ORDER BY SITE.VLD_SITE_ID ) A
LEFT JOIN
(
SELECT VS.SITE_PIC_NAME,NVL(A.NEW_NUM,0) AS NEW_NUM,NVL(A.UPDATE_NUM,0) AS UPDATE_NUM,NVL(A.BIG_NUM,0) AS BIG_NUM FROM VLD_SITE VS
LEFT JOIN (
SELECT VVS.VLD_ENTERPRISE_ID,SUM(DECODE(T.PROJ_PROPERTY, '1', 1, 0)) AS NEW_NUM,
SUM(DECODE(T.PROJ_PROPERTY, '2', 1, 0)) AS UPDATE_NUM,
SUM(DECODE(T.PROJ_PROPERTY, '4', 1, 0)) AS BIG_NUM
FROM C_PROJ_MAIN_TB T
INNER JOIN VLD_SITE VS ON T.VLD_SITE_ID = VS.VLD_SITE_ID
INNER JOIN V_VLD_SITE_ENTERPRISE VVS
ON T.VLD_SITE_ID= VVS.VLD_SITE_ID
WHERE VS.ORG_STATUS = 'A'
AND T.START_DATE <= SYSDATE
AND (T.PLAN_END_DATE IS NULL OR T.PLAN_END_DATE >= SYSDATE)
GROUP BY VVS.VLD_ENTERPRISE_ID
) A ON VS.VLD_SITE_ID=A.VLD_ENTERPRISE_ID
WHERE VS.VLD_ENTITY_TYPE_ID=20
AND VS.ORG_STATUS = 'A'
AND VS.RENDER_ORDER < 9999
ORDER BY VS.VLD_SITE_ID
) B on B.SITE_PIC_NAME=A.SITE_PIC_NAME)
请问怎么弄
------解决思路----------------------
使用union all列转行,然后再行转列