本题目要求编写Insert语句, 计算每位同学获得的总学分,并将所有学生的总学分按学号升序排序后一起插入到totalcredit表中。
当某门课程成绩在60分以上时才能合计计入总学分
如果某学生尚未选修任何课程时,总学分计为0,并插入到totalcredit表中。insert into totalcredit
select sno,sum(credit)
from(
select stu.sno sno,case when sc.grade>=60 then credit else 0 end credit
from stu left outer join sc on stu.sno=sc.sno left outer join cou on sc.cno=cou.cno
group by stu.sno,credit,grade) a
group by sno