Crosstab Query with Dynamic Columns in SQL Server 2008

前端 未结 2 889
生来不讨喜
生来不讨喜 2021-01-16 11:58

I\'m having trouble with a Cross Tab query in SQL Server and was hoping that someone could please help?

I have the following table:

- Student ID - Na         


        
2条回答
  •  暖寄归人
    2021-01-16 12:51

    SELECT studentId,
    StudentName,
    English,
    Maths,
    Computing
    FROM (
    SELECT T.StudentId,
        T.StudentName,
        T.Course,
        T.CourseLevel
    FROM Test T
    ) AS J
    PIVOT(MAX(CourseLevel) FOR Course IN (
            [English],
            [Maths],
            [Computing]
            )) AS P
    

提交回复
热议问题