mysql-面试50题-4

一、查询数据

ymysql-面试50题-2-CSDN博客

二、问题

31.查询课程编号为 01 且课程成绩在 80 分以上的学生的学号和姓名

mysql> select student.sid,student.sname

-> from student,sc

-> where cid="01"

-> and score>=80

-> and student.sid = sc.sid;

+------+--------+

| sid | sname |

+------+--------+

| 01 | 赵雷 |

| 03 | 孙风 |

+------+--------+

2 rows in set (0.00 sec)

32.求每门课程的学生人数

mysql> select sc.CId,count(*) as 学生人数

-> from sc

-> GROUP BY sc.CId;

+------+--------------+

| CId | 学生人数 |

+------+--------------+

| 01 | 6 |

| 02 | 6 |

| 03 | 6 |

+------+--------------+

3 rows in set (0.00 sec)

33.成绩不重复,查询选修「张三」老师所授课程的学生中,成绩最高的学生信息及其成绩

mysql> select student.*, sc.score, sc.cid from student, teacher, course,sc

-> where teacher.tid = course.tid

-> and sc.sid = student.sid

-> and sc.cid = course.cid

-> and teacher.tname = "张三"

-> order by score desc

-> limit 1;

+------+--------+---------------------+------+-------+------+

| SId | Sname | Sage | Ssex | score | cid |

+------+--------+---------------------+------+-------+------+

| 01 | 赵雷 | 1990-01-01 00:00:00 | 男 | 90.0 | 02 |

+------+--------+---------------------+------+-------+------+

1 row in set (0.01 sec)

34.成绩有重复的情况下,查询选修「张三」老师所授课程的学生中,成绩最高的学生信息及其成绩

mysql> select student.*, sc.score, sc.cid from student, teacher, course,sc

-> where teacher.tid = course.tid

-> and sc.sid = student.sid

-> and sc.cid = course.cid

-> and teacher.tname = "张三"

-> and sc.score = (

-> select Max(sc.score)

-> from sc,student, teacher, course

-> where teacher.tid = course.tid

-> and sc.sid = student.sid

-> and sc.cid = course.cid

-> and teacher.tname = "张三"

-> );

+------+--------+---------------------+------+-------+------+

| SId | Sname | Sage | Ssex | score | cid |

+------+--------+---------------------+------+-------+------+

| 01 | 赵雷 | 1990-01-01 00:00:00 | 男 | 90.0 | 02 |

+------+--------+---------------------+------+-------+------+

1 row in set (0.00 sec)

35.查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩

36.查询每门功成绩最好的前两名

37.统计每门课程的学生选修人数(超过 5 人的课程才统计)。

mysql> select sc.cid, count(sid) as cc from sc

-> group by cid

-> having cc >5;

+------+----+

| cid | cc |

+------+----+

| 01 | 6 |

| 02 | 6 |

| 03 | 6 |

+------+----+

3 rows in set (0.00 sec)

38.检索至少选修两门课程的学生学号

mysql> select sid, count(cid) as cc from sc

-> group by sid

-> having cc>=2;

+------+----+

| sid | cc |

+------+----+

| 01 | 3 |

| 02 | 3 |

| 03 | 3 |

| 04 | 3 |

| 05 | 2 |

| 06 | 2 |

| 07 | 2 |

+------+----+

7 rows in set (0.00 sec)

39.查询选修了全部课程的学生信息

40.查询各学生的年龄,只按年份来算

注:对于上面的一些题,后面补

相关推荐
没有bug.的程序员3 小时前
JAVA面试宝典 - 《MyBatis 进阶:插件开发与二级缓存》
java·面试·mybatis
珊瑚里的鱼4 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法
顾林海6 小时前
Android 性能优化:启动优化全解析
android·java·面试·性能优化·zygote
绝无仅有8 小时前
使用LNMP一键安装包安装PHP、Nginx、Redis、Swoole、OPcache
后端·面试·github
绝无仅有8 小时前
服务器上PHP环境安装与更新版本和扩展(安装PHP、Nginx、Redis、Swoole和OPcache)
后端·面试·github
天天扭码11 小时前
很全面的前端面试题——CSS篇(下)
前端·css·面试
Java中文社群11 小时前
面试官:谈谈你AI项目的具体实现?
java·后端·面试
然我11 小时前
react-router-dom 完全指南:从零实现动态路由与嵌套布局
前端·react.js·面试
前端拿破轮12 小时前
刷了这么久LeetCode了,挑战一道hard。。。
前端·javascript·面试
多啦C梦a12 小时前
《设计模式?》前端单例模式保姆级教程:用 Class + 闭包各封装一个 LocalStorage 单例,一次学会!
前端·javascript·面试