SQL 将多个 select 语句合并为单独的列

SQL to combine multiple select statements as separate columns

我正在尝试根据多个 select 条件创建报告,我无法将所有这些连接在一起以获得基于“Nationalcode”的简单报告输出。

我的SQL如下

SELECT * 
FROM
    (SELECT 
         QualificationNationalCode, 
         COUNT(StudentID) AS ASP 
     FROM 
         [Insight].[Report].[Rpt_SIS_Student_Active_Curricula] 
     WHERE  
         StudyPathStatus = 'Active study path' 
     GROUP BY
         QualificationNationalCode) AS XA

    FULL OUTER JOIN

    (SELECT 
         QualificationNationalCode, 
         COUNT(StudentID) AS ACT 
     FROM 
         [Insight].[Report].[Rpt_SIS_Student_Active_Curricula] 
     WHERE  
         TrainingAccountStatus IN ('Active', 'Leave From Enrolment')    
     GROUP BY
         QualificationNationalCode) AS XY

    FULL OUTER JOIN

    (SELECT 
         QualificationNationalCode, 
         COUNT(StudentID) as URCT 
     FROM 
         [Insight].[Report].[Rpt_SIS_Student_Active_Curricula] 
     WHERE  
         Unresulted_CountByTAFECode <> 0    
     GROUP BY 
         QualificationNationalCode) AS XB

    FULL OUTER JOIN

    (SELECT 
         QualificationNationalCode, 
         MAX(LatestRegTermByTAFECode) AS LRWP 
     FROM 
         [Insight].[Report].[Rpt_SIS_Student_Active_Curricula] 
     WHERE  
         ParchmentIssued = 'No' 
     GROUP BY 
         QualificationNationalCode) AS XC

    ON XY.QualificationNationalCode = XA.QualificationNationalCode  
    AND ON XB.QualificationNationalCode = XC.QualificationNationalCode

尝试

SELECT * 
FROM
    (SELECT 
         QualificationNationalCode, 
         COUNT(StudentID) AS ASP 
     FROM 
         [Insight].[Report].[Rpt_SIS_Student_Active_Curricula] 
     WHERE  
         StudyPathStatus = 'Active study path' 
     GROUP BY
         QualificationNationalCode) AS XA

    FULL OUTER JOIN

    (SELECT 
         QualificationNationalCode, 
         COUNT(StudentID) AS ACT 
     FROM 
         [Insight].[Report].[Rpt_SIS_Student_Active_Curricula] 
     WHERE  
         TrainingAccountStatus IN ('Active', 'Leave From Enrolment')    
     GROUP BY
         QualificationNationalCode) AS XY
    ON XY.QualificationNationalCode = XA.QualificationNationalCode  

    FULL OUTER JOIN

    (SELECT 
         QualificationNationalCode, 
         COUNT(StudentID) as URCT 
     FROM 
         [Insight].[Report].[Rpt_SIS_Student_Active_Curricula] 
     WHERE  
         Unresulted_CountByTAFECode <> 0    
     GROUP BY 
         QualificationNationalCode) AS XB
    ON XY.QualificationNationalCode = XB.QualificationNationalCode  

    FULL OUTER JOIN

    (SELECT 
         QualificationNationalCode, 
         MAX(LatestRegTermByTAFECode) AS LRWP 
     FROM 
         [Insight].[Report].[Rpt_SIS_Student_Active_Curricula] 
     WHERE  
         ParchmentIssued = 'No' 
     GROUP BY 
         QualificationNationalCode) AS XC
     ON XB.QualificationNationalCode = XC.QualificationNationalCode