当前位置:网站首页>MySQL面试真题(二十五)——常见的分组比较场景
MySQL面试真题(二十五)——常见的分组比较场景
2022-06-23 03:58:00 【Socialphobia_FOGO】
现在有三个表,“学生表”,“课程表”,“成绩表”。
“学生表”记录了学生的基本信息,有“学号”、“姓名”、“出生日期”、“性别”。
“成绩表”记录了学生选修课程的成绩,包括“学号”,选修的“课程号”以及对应课程的“成绩”。
“课程表”记录了学生选修的课程信息,包括课程号、课程名称及其对应的“教师号”
现在要查找出每门课程中成绩最好的学生的姓名和该学生的课程及成绩。
需要注意:可能出现并列第一的情况。
#解法一:
SELECT 姓名,课程名称,成绩
FROM
(SELECT *,
dense_rank()over(PARTITION BY 课程号 ORDER BY 成绩 DESC) AS 排名
FROM 成绩表
JOIN 课程表
USING(课程号)
JOIN 学生表
USING(学号))a
WHERE 排名=1
ORDER BY 课程名称
#解法二:
SELECT 姓名,课程名称,成绩
FROM 成绩表
JOIN 课程表
USING(课程号)
JOIN 学生表
USING(学号)
WHERE (课程号,成绩) IN (SELECT 课程号,MAX(成绩) FROM 成绩表 GROUP BY 课程号)
ORDER BY 课程名称
结果如下:
边栏推荐
- FS4059A与FS5080E充电芯片的区别
- 英集芯ip6806无线充电方案5W过Qi认证外围精简14颗器件
- Today's sleep quality record 80 points
- Ip6809 three coil 15W wireless charging transmitter scheme IC British chip
- 奇门遁甲辅助决策软件
- H5 适配全面屏
- Konva series tutorial 1:what is konva?
- Win11应用商店下载的软件怎么移到桌面
- What does it mean to open more accounts? Why open more accounts? How to implement it safely?
- 啊哈C语言 第8章 游戏时间到了(第29讲)
猜你喜欢

英文字母pc是什么意思,互联网的pc指的是什么

GO语言-panic和recover

What is the reason for the black screen of the computer monitor when the computer is turned on? What should I do about the black screen of the computer monitor

Lihongyi, machine learning 5 Tips for neural network design

Yingjixin ip6806 wireless charging scheme 5W Qi certified peripheral simplified 14 devices

MDM数据清洗功能开发说明

JDBC introductory learning (II) encapsulation tool class
![[opencv450] inter frame difference method](/img/ad/c8a56e27d78cea581deb1874620613.png)
[opencv450] inter frame difference method

Differences between fs4059a and fs5080e charging chips

Un processus GC complet pour le principe JVM
随机推荐
Win11不能录制音频怎么办?Win11无法录入声音的解决方法
Win software - (net framework) processed the certificate chain but terminated in a root certificate that is not trusted by the trusted provider
人脸识别 确定阈值
英集芯ip6806无线充电方案5W过Qi认证外围精简14颗器件
fastjson中的@JSONField注解
Un processus GC complet pour le principe JVM
About replay attack and defense
AI艺术的基因工程?使用 #Artbreeder 改变图像的任意形态
Implementation of MySQL custom sequence number
Shifu, the open source development platform of the Internet of things, is open for internal testing! Release of the first version of technical documents
啊哈C语言 第7章 有了它你能做更多的事(第27-28讲)
App automated test appium advanced
Mobile power fast charging qc3.0 scheme chip ip5318 fast charging scheme
The weak are as irritable as tigers, the strong are as calm as water, and the really powerful have already given up their emotions
Lottery DDD code
云原生大趋势下的容器化技术现状与发展
Ip6809 three coil 15W wireless charging transmitter scheme IC British chip
Win11应用商店一直转圈解决办法
Memory model of JVM principle
Jenkins安装部署以及自动构建和发布jar应用