当前位置:网站首页>mysql 中 in 的用法
mysql 中 in 的用法
2022-08-02 08:00:00 【暮晓引流软件】
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的关系分开了,分开后就可能出现结果列错位的情况,可能名字和他的分数对不上。
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- 基于PyTorch的flappy bird游戏
- Elasticserch 自定义字段,用户会频繁的创建和删除字段,怎么设计mapping?
- [ansible] playbook explains the execution steps in combination with the project
- 用户身份标识与账号体系实践
- (Note)阿克西斯ACASIS DT-3608双盘位硬盘阵列盒RAID设置
- R语言plotly可视化:使用plotly可视化模型预测真阳性率(True positive)TPR和假阳性率(False positive)FPR在不同阈值(threshold)下的曲线
- 知识点滴 - 为什么一般不用铜锅做菜
- A young man with strong blood and energy actually became a housekeeper. How did he successfully turn around and change careers?
- RIP综合实验
- 软件测试技术之解析图灵测试离我们还有多远
猜你喜欢
随机推荐
多表的查询
解决IDEA安装安装插件慢问题
QT web 开发 - 笔记 - 3
A young man with strong blood and energy actually became a housekeeper. How did he successfully turn around and change careers?
Biotin-C6-amine|N-生物素基-1,6-己二胺|CAS:65953-56-2
传递泛型给JSX元素
redis的安装与应用
Database Plus 的云上之旅:SphereEx 正式开源 ShardingSphere on Cloud 解决方案
近期在SLAM建图和定位方面的进展
Biotin - LC - Hydrazide | CAS: 109276-34-8 | Biotin - LC - Hydrazide
小说里的编程 【连载之二十二】元宇宙里月亮弯弯
WebRTC系列-SDP之编码信息收集
MySQL优化之慢日志查询
IO进程线程->进程->day4
商业智能平台BI 商业智能分析平台 如何选择合适的商业智能平台BI
Wang Xuegang - compiled shipment line file
IO process thread -> process -> day4
17、生成长图,并上传至服务器
Appium swipe problem
Biotin-EDA|CAS:111790-37-5| Ethylenediamine biotin

![[ansible]playbook结合项目解释执行步骤](/img/fe/82b8562075fef33490d5aae7e809f5.png)
![Three types of [OC learning notes] Block](/img/40/edf59e6e68891ea7c9ab0481fe7bfc.png)





