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 
相关推荐
!!!5252 分钟前
Java Stream 流笔记
java·笔记
m0_7482509320 分钟前
Spring Boot 2.7.x 至 2.7.18 及更旧的版本,漏洞说明
java·spring boot·后端
mua码1 小时前
二十三种设计模式
java·设计模式
飞3001 小时前
腾讯集团软件开发-后台开发方向内推
java·mysql·业界资讯
码熔burning3 小时前
(十 五)趣学设计模式 之 命令模式!
java·设计模式·命令模式
暴怒的代码3 小时前
云原生监控篇——全链路可观测性与AIOps实战
数据库·sql·mysql
计算机-秋大田6 小时前
基于Spring Boot的乡村养老服务管理系统设计与实现(LW+源码+讲解)
java·vue.js·spring boot·后端·课程设计
盖盖衍上6 小时前
Java 泛型(Generics)详解与使用
java·开发语言·windows
没有十八岁7 小时前
云创智城YunCharge 新能源二轮、四轮充电解决方案(云快充、万马爱充、中电联、OCPP1.6J等多个私有单车、汽车充电协议)之新能源充电行业系统说明书
java·数据库·spring·汽车
小萌新上大分8 小时前
Minio搭建并在SpringBoot中使用完成用户头像的上传
java·spring boot·后端·minio·minio搭建·头像上传·minio入门