我有這個SQL語句試圖聯合兩個查詢的結果。我怎樣才能得到我使用這條SQL語句尋找的輸出
SELECT s.SectionIndex, COUNT(*) AS [# Drops], s.Name AS section_name, c.DisplayName AS course_name
FROM Enrollments e
JOIN Sections s on s.SectionIndex = e.SectionIndex
JOIN Courses c on c.CourseIndex = s.CourseIndex
WHERE (CAST(StartDate AS DATE) BETWEEN '2014-06-30' AND '2015-06-30') AND (e.Status like 'DROPPED%')
GROUP BY s.SectionIndex, s.Name, c.DisplayName
UNION ALL
SELECT s.SectionIndex, COUNT(*) AS [# Completes], s.Name AS section_name, c.DisplayName AS course_name
FROM Enrollments e
JOIN Sections s on s.SectionIndex = e.SectionIndex
JOIN Courses c on c.CourseIndex = s.CourseIndex
WHERE (CAST(StartDate AS DATE) BETWEEN '2014-06-30' AND '2015-06-30') AND (e.Status like 'complete%')
GROUP BY s.SectionIndex, s.Name, c.DisplayName
ORDER BY s.SectionIndex
結果集看起來像這樣,我認爲這是準確的。例如,對於SectionIndex 996,這些投入是3和完成1.前4個部分只有投入。
結果集。
SectionIndex xxx
# drops xx
# completions xx
SectionIndex xxx
# drops xx
# completions xx
。 。 。
謝謝你對此的想法。