当前位置:网站首页>SQL中HAVING和WHERE的区别
SQL中HAVING和WHERE的区别
2022-04-23 14:47:00 【Jan_ssen】
在SQL中,一般的增删查改语句都是使用WHERE关键词来对特殊的字段进行检索,但是当SELECT查询语句中使用到GROUP BY来进行分组查询时,对于分组后的结果进行条件过滤则需要用到HAVING关键词。
简单来说,就是WHERE用于分组前,HAVING用于分组后!
例如,查找班级号小于四的班级的平均分
SELECT class, AVG(score)
FROM test
WHERE class<4
GROUP BY class;
SELECT class, AVG(score)
FROM test
GROUP BY class
HAVING class<4;
以上两种写法都正确,只不过前者是先过滤再分组,后者是先分组再过滤。
当然,这个例子只是个个例罢了,很多情况下必须要筛选分组后的数据,那么HAVING就会派上用场了。
版权声明
本文为[Jan_ssen]所创,转载请带上原文链接,感谢
https://blog.csdn.net/littlest_white/article/details/124305549
边栏推荐
- 金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
- 一个月把字节,腾讯,阿里都面了,写点面经总结……
- [stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
- What is the main purpose of PCIe X1 slot?
- PWM speed regulation control system of DC motor based on 51 single chip microcomputer (with complete set of data such as Proteus simulation + C program)
- 51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
- Outsourcing for four years, abandoned
- Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
- 利用 MATLAB 编程实现最速下降法求解无约束最优化问题
- 1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
猜你喜欢
抑郁症治疗的进展
利用 MATLAB 编程实现最速下降法求解无约束最优化问题
Thread synchronization, life cycle
PCIe X1 插槽的主要用途是什么?
8.3 语言模型与数据集
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
Programming philosophy - automatic loading, dependency injection and control inversion
QT actual combat: Yunxi chat room
随机推荐
ASEMI整流模块MDQ100-16在智能开关电源中的作用
51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time
想要成为架构师?夯实基础最重要
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
Detailed explanation of C language P2 selection branch statement
Go basic reflection
如何打开Win10启动文件夹?
On the insecurity of using scanf in VS
raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
数组模拟队列进阶版本——环形队列(真正意义上的排队)
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Solve the problem of SSH configuration file optimization and slow connection
SQLSERVER事物与锁的问题
Programming philosophy - automatic loading, dependency injection and control inversion
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
解决computed属性与input的blur事件冲突问题
select 同时接收普通数据 和 带外数据
压缩映射定理