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 
相关推荐
Leo July13 小时前
【Java】Spring Security 6.x 全解析:从基础认证到企业级权限架构
java·spring·架构
星火开发设计13 小时前
C++ 数组:一维数组的定义、遍历与常见操作
java·开发语言·数据结构·c++·学习·数组·知识
码道功成13 小时前
Pycham及IntelliJ Idea常用插件
java·ide·intellij-idea
消失的旧时光-194314 小时前
第四篇(实战): 订单表索引设计实战:从慢 SQL 到毫秒级
java·数据库·sql
それども14 小时前
@ModelAttribute vs @RequestBody
java
雨中飘荡的记忆15 小时前
深度详解Spring Context
java·spring
Tao____15 小时前
JAVA开源物联网平台
java·物联网·mqtt·开源·ruoyi
yqd66615 小时前
SpringSecurity的使用
java·spring
仙俊红15 小时前
Java Map 家族核心解析
java·开发语言
一嘴一个橘子16 小时前
springMvc 接收参数、cookie、header
java