--查询具有不同特征的学生信息,特征要求自行定义
--查询所有信息系统专业的男生的姓名,学号
select Sno,Sname from Student19377056 where Sdept='IS' and Sgender='男'
--查询所有姓李的2017级学生
select Sno,Sname from Student19377056 where Sname like '李%' and Syear = 2017
--查询所有选修8003课程的2019级学生
select Student19377056.Sno,Sname from Student19377056,Sc19377056
where Student19377056.Sno = Sc19377056.Sno and Cno=8003 and Syear=2017
--查询所有选择2学分课程的同学成绩的前5名
select top 5 Student19377056.Sno,Sname,Sc19377056.Cno,Cname,Grade from Student19377056,Course19377056,Sc19377056
where Student19377056.Sno=Sc19377056.Sno and Sc19377056.Cno=Course19377056.Cno and
Ccredit=2 order by Grade desc
--每门课的选课人数和平均成绩
select Cno,count(Cno) people_number,avg(Grade) avg_grade from Sc19377056 group by Cno
--有不及格课程学生的姓名、学号、专业
select distinct Student19377056.Sno,Sname,Sdept from Student19377056,Sc19377056
where Student19377056.Sno=Sc19377056.Sno and grade<60
--将2017年入学,必修课成绩依然有不及格状态的同学,将其学籍状态标记为"暂缓毕业"
update Student19377056 set Sroll = '暂缓毕业' where Sno in
(select Student19377056.Sno from Student19377056,Sc19377056 where Student19377056.Sno=Sc19377056.Sno and Syear=2017 and grade<60)
--定义视图:提供每门课的学生平均分
create view grade_student(Cno,avg_grade) as select Cno,avg(Grade) from Sc19377056 group by Cno
select * from grade_student
--删除从来没有人选修的课程信息
delete from Course19377056 where Cno not in (select Course19377056.Cno from Sc19377056,Course19377056 where Sc19377056.Cno=Course19377056.Cno)
--8004课程被去掉