紧跟上一节,我们创建了四个表:
Student、Teacher、Course、Score
接下来就是实际的一些操作了:1.求每门课程的学生人数。
select course.cname '课程名称',count(*) '人数' from score,course where score.CId=course.CId group by score.CId
2.查询课程编号为 01 且课程成绩在 80 分及以上的学生的学号和姓名
select a.sid,a.sname from Student a ,Score b where a.sid=b.sid and b.cid='01' and b.scoreore >=80;
3.统计每门课程的学生选修人数(超过 5 人的课程才统计)
select b.cname '课程',count(*) from course a,score b where a.cid=b.cid group by a.cid having count(*)>5;
4.检索至少选修两门课程的学生学号
select sid from score group by sid having count(cid)>=2;
未完待续。。。