我想我的桌子水平旋轉 -無法執行查詢分組
的表如下所示:
Master_Choicecode
ChoiceCode MainCourseId CourseLevelId InstituteId
Master_MainCourse
MainCourseId MainCourseName CourseLevelId CourseProgram
11 x 1 abc
12 y 2 xyz
Master_CourseLevel
CourseLevelId CourseLevelName
1 deg
2 Dip
Master_Institute
Instituteid InstituteName Statusid
1001 Insti1 100
1002 Insti2 200
Master_InstituteStatus
StatusId StatusName
100 Status1
200 Status2
現在使用所有這些表我想說明這一點:
CourseProgram CourseLevelName Status1(from Master_InstituteStatus) Status2(from Master_InstituteStatus)
abc Deg Count of institutes belonging to status1 Count of institutes belonging to status2
現在,這是我曾嘗試:
SELECT B.CourseProgram,C.CourseLevelName,
case when E.InstituteStatusName =' Status1' then COUNT(*) else null end as Status1,
case when E.InstituteStatusName =' Status2' then COUNT(*) else null end as Status2,
FROM Master_ChoiceCode A
inner join Master_MainCourse B on A.MainCourseID=B.MainCourseID
inner join Master_CourseLevel C on A.CourseLevelID=C.CourseLevelID
inner join Master_Institute D on A.InstituteID=D.InstituteID
inner join Master_InstituteStatus1 E on D.InstituteStatusID1=E.InstituteStatusID
where B.CourseLevelID IN(1,2)
GROUP BY B.CourseProgram,A.CourseLevelID,C.CourseLevelName,E.InstituteStatusName
order by B.CourseProgram,C.CourseLevelName;
但是有了這個,我得到這樣的輸出:
CourseProgram CourseLevelName Status1(from Master_InstituteStatus) Status2(from Master_InstituteStatus)
abc Deg Count of institutes belonging to status1
abc Deg Null Count of institutes belonging to status1
我得到的解決方案是使用旋轉......但我不KNW如何泥質我用透視我目前query.Please幫助我..
哎感謝名單一lottt YAA ......它的工作:) –