SQL经典题型

  1. 查询不在表里的数据,一张学生表,一张学生的选课表,要求查出没有选课的学生?
sql 复制代码
select students.student_name from students left join course_selection on students.student_id=course_selection.student_id where course_selection.student_id is null
  1. 查找第N高的数据,查找课程编号为"01"的成绩第三高的学生,如果不存在则返回null
sql 复制代码
select IFNULL((select scores.score from scores order by scores.score desc limit 1 offset 2) ,null) as "第三高的成绩"
  1. 分组排序,按成绩从大到小排序如80,80,76,70,50 对应的排序为1,1,3,4,5
sql 复制代码
select  *,RANK() over(ORDER BY scores.score DESC) as "排名" from scores


  1. 连续出现N次问题,学生连续3个学号相邻的学生出现年龄相同的年龄
sql 复制代码
select distinct a.age from students a,students b,students c where a.student_id=b.student_id+1 and b.student_id=c.student_id+1 and a.age=b.age and b.age=c.age 
相关推荐
ss2731 分钟前
ThreadPoolExecutor:自定义线程池参数
java·开发语言
invicinble21 分钟前
关于fastjson的具体使用案例
java
墨着染霜华38 分钟前
Spring Boot整合Kaptcha生成图片验证码:新手避坑指南+实战优化
java·spring boot·后端
码界奇点1 小时前
Java外功核心7深入源码拆解Spring Bean作用域生命周期与自动装配
java·开发语言·spring·dba·源代码管理
czlczl200209251 小时前
Spring Security @PreAuthorize 与自定义 @ss.hasPermission 权限控制
java·后端·spring
我爱学习好爱好爱1 小时前
Prometheus监控栈 监控java程序springboot
java·spring boot·prometheus
老华带你飞1 小时前
考试管理系统|基于java+ vue考试管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
阿蒙Amon1 小时前
C#每日面试题-属性和特性的区别
java·面试·c#
懒惰蜗牛1 小时前
Day66 | 深入理解Java反射前,先搞清楚类加载机制
java·开发语言·jvm·链接·类加载机制·初始化
赵庆明老师2 小时前
VS2026扩展插件Visual Commander
java·开发语言