当前位置:网站首页>mysql 中 in 的用法
mysql 中 in 的用法
2022-07-30 05:15:00 【m0_67392931】
1. select * from student s where s.id in (20,30);
查询id是20或者是30,等同于select * from student s where s.id = 20 or s.id = 30;
2.select * from student s where s.id in (select age from student);
查询id是age数组里面的,单个字段只能in查询结果是单行的。
很明显后面括号的 select age from student 查出来只有age这一列,假如括号的查询查出来的age是下面图列

那么此时查询就等价于select * from student s where s.id in (64,57,32,24,35,55);
3.select * from student s where (s.class , s.score) in (select class , max(score) from student group by class)
既然能单个字段in单行结果,那么多个字段就能in多行结果了。
这个sql表示:查询每个班级中分数最高的学生的所有数据
注意,此时的name和class是不会错位的,你本来就是按着匹配的class和score去in匹配class、score的结果集,所以数据不会出错的。
如果你写成这样:
select * from student s where s.classin (select class from student group by class) and s.score in (select max(score) from student group by class);
就把class和score的关系分开了,分开后就可能出现结果列错位的情况,可能名字和他的分数对不上。
边栏推荐
- This article will take you through js to deal with the addition, deletion, modification and inspection of tree structure data
- [Redis Master Cultivation Road] Jedis - the basic use of Jedis
- Seata异常:endpoint format should like ip:port
- Hexagon_V65_Programmers_Reference_Manual (11)
- [Verilog] HDLBits Problem Solution - Circuits/Combinational Logic
- Path dependence: the poor hard science to counter attack breakthrough
- JVM 垃圾回收 超详细学习笔记(二)
- 工具 | 常用 PostgreSQL 预防数据丢失方案
- 微信支付及支付回调
- Kyligence 亮相第五届南方信息大会并获评“CIO 优选数字化服务商”
猜你喜欢

Hexagon_V65_Programmers_Reference_Manual (12)

An old programmer's summary review of 2020, how to become more awesome in 2021

oracle触发器的自治事务

MySQL Basics (DDL, DML, DQL)

JVM 类加载机制 超详细学习笔记(三)

即刻报名|如何降低云上数据分析成本?

文档在线化管理系统Confluce使用
![[Redis Master Cultivation Road] Jedis - the basic use of Jedis](/img/e3/0c6efd03432a01f857796f0bf648ef.png)
[Redis Master Cultivation Road] Jedis - the basic use of Jedis

mysql基础(4)

程序员大保健指南,给自己的身心偶尔放松的机会
随机推荐
【小程序项目开发 -- 京东商城】uni-app 商品分类页面(下)
Recursive Optimization of Fibonacci Sequences "Memo Recursion"
ugly programmer
文档在线化管理系统Confluce使用
MySQL夺命10问,你能坚持到第几问?
【LeetCode】Day107-除自身以外数组的乘积
VisualStudio2022 local debugging entry is particularly slow problem solving
DLL description (1)
开源之夏 2022 与您相约!
[Redis Master Cultivation Road] Jedis - the basic use of Jedis
翻译 | 解读首部 Kubernetes 纪录片
go language study notes 3
一个老程序员的2020年总结回顾,2021年如何变的更牛逼
pytorch官网中如何选择以及后面的安装和pycharm测试步骤
IGBT wafers used in photovoltaic inverters
2022鹏城杯web
RadonDB MySQL on K8s 2.1.4 发布!
是时候不得不学英语了,技多不压身,给自己多条路
mysql基础(4)
MySQL索引从入门到深入学习