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 
相关推荐
十五年专注C++开发4 分钟前
MySql中各种功能用sql语句实现总结
数据库·sql·mysql
云烟成雨TD9 分钟前
Spring AI 1.x 系列【57】动态工具发现:Tool Search Tool
java·人工智能·spring
zfoo-framework25 分钟前
[修改代码使用]codex官方app中使用中转(不需要cc-switch) 1.config.toml 2.sk方式登录
java
逍遥德1 小时前
MQTT教程详解-05.SpringBoot集成mqtt client 性能分析
java·spring boot·spring·mt
云烟成雨TD1 小时前
Spring AI 1.x 系列【54】Retry 机制分析
java·人工智能·spring
weixin_523185321 小时前
Collections.unmodifiableMap详解:真的不可修改吗?
java·linux·前端
点燃大海1 小时前
SpringAI构建智能体
java·spring boot·spring·springai智能体
xier_ran1 小时前
【infra之路】02_RadixAttention与KV_Cache管理
java·spring boot·spring
黑马师兄1 小时前
RAG混合检索深度解析:让AI真正找到你要的内容
java·人工智能·ai·agent·rag·ai-native
码客日记1 小时前
Spring Boot 配置文件敏感信息加密(Jasypt 企业级完整方案)
java·spring boot·git