经典SQL语句大全以及50个常用的sql语句 (9)

44、统计每门课程的学生选修人数(超过10人的课程才统计)。要求输出课程号和选修人数,查询结果按人数降序排列,查询结果按人数降序排列,若人数相同,按课程号升序排列 

select C# as 课程号,count(*) as 人数

from sc 

group by C#

order by count(*) desc,c# 

45、检索至少选修两门课程的学生学号

select S# 

from sc 

group by s#

having count(*) > = 2

46、查询全部学生都选修的课程的课程号和课程名

select C#,Cname 

from Course 

where C# in (select c# from sc group by c#) 

47、查询没学过“叶平”老师讲授的任一门课程的学生姓名

select Sname from Student where S# not in (select S# from Course,Teacher,SC where Course.T#=Teacher.T# and SC.C#=course.C# and Tname=\'叶平\');

48、查询两门以上不及格课程的同学的学号及其平均成绩

select S#,avg(isnull(score,0)) from SC where S# in (select S# from SC where score <60 group by S# having count(*)>2)group by S#;

49、检索“004”课程分数小于60,按分数降序排列的同学学号

select S# from SC where C#=\'004\'and score <60 order by score desc;

50、删除“002”同学的“001”课程的成绩

delete from Sc where S#=\'001\'and C#=\'001\';

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zggszd.html