/*删除1002同学的001课程的成绩*/deletefrom SC where Sid=1002and Cid='001';/*查询李姓同学的名单*/select Sname from Student where Sname like'李%';/*查询004课程小于60分的同学学号,按分数倒序显示*/select Sid from SC WHERE Cid='004'and score<60orderby score desc;/*查询每门课程选修人数*/select Cid,count(*) from SC groupby Cid;/*查询至少学过两门课程的学生学号*/select Sid from SC groupby Sid havingcount(*)>=2;/*查询全部学生都选修了的课程编号与名称*/select Cid,Cname from Course where Cid in(select Cid from sc groupby Cid);/*查询不同课程成绩相同的学号、课程号、成绩*/selectDISTINCT a.sid,a.cid,b.score from sc a,sc b where a.score=b.score and a.cid<>b.cid;/*查询所有同学的选修课情况(姓名,课程,分数)*/select a.sname,b.cname,c.score from student a,course b,sc c WHERE a.sid=c.sid and b.cid=c.cid;/*查询同名同姓同学名单,并统计人数*/SELECT sname,count(*) from student groupby sname havingCOUNT(*)>1;/*查询姓李的老师人数*/selectcount(DISTINCT(tname)) from teacher where tname like'李%';/*查询平均成绩大于60分的同学的学号和平均成绩*/select sid,avg(score) from sc GROUPby sid havingAVG(score)>60;/*查询所有同学的学号、姓名、选课数、总成绩*/select a.Sid,a.Sname,count(b.Cid),sum(b.score)
from student a leftjoin sc b on a.Sid=b.Sid
groupby a.Sid,Sname;/*查询001课程比002课程成绩高的所有学生学号*/select a.Sid from
(select Sid,score from sc where Cid='001') a,
(select Sid,score from sc where Cid='002') b
where a.score>b.score and a.Sid=b.Sid;/*查询没学过叶平老师课程的同学学号与姓名*/select a.Sid,a.Sname from student a
where a.Sid notin(selectdistinct(b.Sid)
from sc b,course c,teacher d
where b.Cid=c.Cid and d.Tid=c.Tid and d.Tname='叶平');/*查询不及格的课程*/select Cname from Course a,SC b where a.Cid=b.Cid
and b.score<60;/*查询两门以上不及格课程的同学的学号及平均成绩*/select Sid,avg(score) from SC where Sid
in(select Sid from SC where score<60groupby Sid
havingcount(*)>2) groupby Sid;/*统计各科成绩达到A、B、C、D的各有多少人*/select cname,sum(casewhen score>=90and score<=100then1else0end) as'A',sum(casewhen score>=80and score<=90then1else0end) as'B', sum(casewhen score<80then1else0end) as'C'from sc,course
where sc.cid=course.cid groupby cname;/*查询没有学全所有课程的同学学号与姓名*/select a.Sid,a.Sname from Student a,SC b
where a.Sid=b.Sid groupby a.Sid,a.Sname
havingcount(*)<(selectcount(*) from Course);/*查询只选修了一门课程的全部同学的学号和姓名*/select a.Sid,a.Sname,count(*) from Student a,SC b
where b.Sid=a.Sid groupby b.Sid,a.Sname havingcount(*)=1;/*查询各科成绩前三名的记录(不考虑并列)*/select Sid,Cid,Score from SC a where
(selectcount(*) from SC b where b.Cid=a.Cid and b.Score>=a.Score)<=3;/*查询学过叶平老师所有课程的同学学号与姓名*/select Sid,Sname from Student where Sid in(select Sid from SC a,Course b,Teacher c
where a.Cid=b.Cid and b.Tid=c.tid and c.Tname='叶平'groupby Sid
havingcount(a.Cid)=(selectcount(Cid) from Course d,Teacher e
where e.Tid=d.Tid
and e.Tname='叶平'));