当前位置:网站首页>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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- 构建Flink第一个应用程序
- Redisson distributed lock source code analysis for high-level use of redis
- 按键控制流水灯(计时器)
- Data Middle Office: Started in Ali, Prosperous in DaaS
- 典型的一次IO的两个阶段是什么?阻塞、非阻塞、同步、异步
- HCIP 第六天
- MySQL压缩包方式安装,傻瓜式教学
- 设置 height: auto 却无法触发 transition 动画的解决方案
- 3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
- 牛客2022 暑期多校4 D Jobs (Easy Version)(递推优化策略)
猜你喜欢

Figure robot software digital twin station oil and gas pipelines, oil and gas transportation control platform

Button to control the running water light (timer)

静态路由综合实验

cas: 139504-50-0 Maytansine DM1|Mertansine|

Biotin-EDA|CAS:111790-37-5| 乙二胺生物素
![MFC最详细入门教程[转载]](/img/5d/655e75f6b8a547fefe0137a9b11536.png)
MFC最详细入门教程[转载]
![[ansible]playbook结合项目解释执行步骤](/img/fe/82b8562075fef33490d5aae7e809f5.png)
[ansible]playbook结合项目解释执行步骤

【开源项目】X-TRACK源码分析

按键控制流水灯(计时器)

工程师如何对待开源 --- 一个老工程师的肺腑之言
随机推荐
node(三) 模块化
读入、输出优化
@RequestParam使用
典型的一次IO的两个阶段是什么?阻塞、非阻塞、同步、异步
mysqldump --set-gtid-purged=OFF
@Repository详解
Biotin-LC-Hydrazide|CAS:109276-34-8|生物素-LC-酰肼
MySQL压缩包方式安装,傻瓜式教学
R language plotly visualization: use the plotly visualization model to predict the true positive rate (True positive) TPR and false positive rate (False positive) FPR curve under different thresholds
如何做好项目管理
基于PyTorch的flappy bird游戏
7.联合索引(最左前缀原则)
理论问题与工程问题的差异在哪里?
I.MX6U-ALPHA开发板(EPIT定时器实验)
Stop mental exhaustion Daily sharing
Write a small game in C (three chess)
[OC学习笔记]weak的实现原理
IO process thread -> process -> day4
如何建立私域流量?私域流量对企业有什么好处?
Flink 程序剖析