1
我一直在尋找關於我的問題幾個小時的答案。SQL Server:樞軸多個聚合體
我現在的表:
StudentName Course Correct Wrong Blank Score
-------------------------------------------------
Student1 Math 38 2 0 95
Student1 English 45 5 0 90
...
Student2 Math 38 2 0 95
Student2 English 45 5 0 90
我要的是:
Math English
StudentName Correct Wrong Blank Score Correct Wrong Blank Score
Student1 38 2 0 95 45 5 0 90
Student2 38 2 0 95 45 5 0 90`
...
SELECT dbo.tbl_Students.StudentName,
dbo.tbl_CourseCategories.CourseCategory,
dbo.tbl_GeneralTestsScores.Correct,
dbo.tbl_GeneralTestsScores.Wrong,
dbo.tbl_GeneralTestsScores.NotAnswered,
dbo.tbl_GeneralTestsScores.Score
FROM
dbo.tbl_AcademicTermsStudents
INNER JOIN
dbo.tbl_Students ON dbo.tbl_AcademicTermsStudents.StudentID = dbo.tbl_Students.StudentID
INNER JOIN
dbo.tbl_GeneralTestsScores
INNER JOIN
dbo.tbl_CourseCategories
ON dbo.tbl_GeneralTestsScores.CourseCategoryID = dbo.tbl_CourseCategories.CourseCategoryID
ON dbo.tbl_AcademicTermsStudents.StudentID = dbo.tbl_GeneralTestsScores.StudentID
Order By StudentName
我搜索了很多網頁的任何不能與解決方案告終。
謝謝。
編輯:我也願意接受以下的解決方案......
StudentName Math_C Math_W Math_B Math_S English_C English_W English_B English_S
Student1 38 2 0 95 45 5 0 90
Student2 38 2 0 95 45 5 0 90`
你會對c#中的客戶端解決方案感到滿意嗎? http://www.codeproject.com/Articles/796651/Client-Side-Multi-Column-Dynamic-Pivot –
不要在'SQL'中嘗試使用應用程序層。另外兩行Header在'SQL'中是不可能的 –
感謝您的評論。 – Meliksah