【发布时间】:2016-06-10 14:19:02
【问题描述】:
几个小时以来,我一直在寻找有关我的问题的答案。
我的当前表:
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# 中的客户端解决方案感到满意吗? codeproject.com/Articles/796651/…
-
不要在
SQL中这样做,尝试使用应用层。SQL中也不可能有两行 Header -
感谢您的 cmets。
标签: sql-server database dynamic pivot multiple-columns