--修改科目名到學生特長字段,分數大於140分,多個科目大於140分則取其中一個
SELECT ROW_NUMBER() OVER(PARTITION BY t.StudentID,t.StudentName ORDER BY t.CourseName) as GroupNum,
t.StudentID,t.StudentName,t.CourseName into #StudentGood from
(SELECT DISTINCT b.StudentID,b.StudentName,c.CourseName FROM StudentScore as a left join Student as b on a.StudentID=b.StudentID
left join Course as c on a.CourseID=c.CourseID WHERE a.Score>140) as t;
update Student set Good=b.CourseName from #StudentGood as b where Student.StudentID=b.StudentID and b.GroupNum=1
drop table #StudentGood