立即学习:https://edu.csdn.net/course/play/4364/77156?utm_source=blogtoedu
# 先创建视图查询所需信息
create view smark
as
select a.StudentID, a.Sname, c.subjectName, b.score
from TStudent a join TScore b on a.StudentID = b.StudentID join TSubject c on b.subjectID = c.subjectID
# 再转换列->行名,然后使用AVG()或SUM()求某学生各科目的成绩
create view as Vmark
as
select studentid 学号, sname 姓名,
AVG(case subject when '计算机网络' then mark END) 计算机网络,
AVG(case subject when '数据结构' then mark END) 数据结构,
AVG(case subject when 'JAVA开发' then mark END) JAVA开发
from smark
group by 学号