如何将行转换为列并填充另一个表

时间:2017-09-27 16:08:22

标签: sql

我有三个表dbo.Student col(StudentID,学生姓名和

Subjects                Test
---------------         ----------------
subjectId int           StubjectId int foreignkey from Subjects
Subject Name            StudentID int  foreignkey from Student
                        Marks int

现在我需要显示测试结果为

Student Name     Math   Geo 
----------------------------
Michael          90     67

1 个答案:

答案 0 :(得分:0)

当您发布SQL问题时,请包含架构和测试数据的脚本

您的初始SQL将类似于

select name, subjectname, marks
    from test t
    inner join student s on t.studentid = s.studentid
    inner join subject su on t.subjectid = su.subjectid 

then you will need to pivot it 2 times