找出所有课程高于80分的学生

有2个表   学生表(Student)  成绩表(grade)

 

一、方法1 反向求解

可以从反面求解,只要有一门课程不满足条件,则该学生不再考虑   select distinct g.no from grade g where g.socre<80

 

然后在学生表中反向求解学生 ,条件为学号不在上面查询的集合中的  

select t.name,t.no from student t where t.no not in (
select distinct g.no from grade g where g.socre<80)  

 

 

 二、方法2  使用having min()与group by 

select m.name from (  select t.name, t.no, g.class_no, g.socre

from student t
  left join grade g
    on g.no = t.no) m
    group by m.name
having min(m.socre)>= 83

三、方法3  使用 not exist 


select *
from student t
where t.no not in (select distinct a.no
from grade a
where not exists (select 1
from grade b
where b.socre < 80
and b.no = a.no))

 

posted @   凉了记忆  阅读(438)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
历史上的今天:
2020-06-16 layui子页面获取父页面对象并传值,设值
2020-06-16 layui获取当前行点击对象和行数
点击右上角即可分享
微信分享提示