mysql的一些常用操作(二)

我们两清 提交于 2019-12-01 01:49:52

紧跟上一节,我们创建了四个表:

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;

 

 未完待续。。。

 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!