当前位置:网站首页>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
边栏推荐
- OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
- QT interface optimization: double click effect
- MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
- 2-Go变量操作
- Swift - literal, literal protocol, conversion between basic data types and dictionary / array
- Sword finger offer II 019 Delete at most one character to get palindrome (simple)
- [proteus simulation] automatic range (range < 10V) switching digital voltmeter
- Arduino for esp8266串口功能简介
- 解决computed属性与input的blur事件冲突问题
- 金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
猜你喜欢
一款不错的工具:aardio
L'externalisation a duré quatre ans.
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
OpenFaaS实战之四:模板操作(template)
自动化的艺术
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
抑郁症治疗的进展
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
8.4 循环神经网络从零实现
随机推荐
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
2-GO variable operation
The initial C language framework is suitable for review and preliminary understanding
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
Explain TCP's three handshakes in detail
GIS数据处理-cesium中模型位置设置
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
【Proteus仿真】自动量程(范围<10V)切换数字电压表
Matrix exchange row and column
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
L'externalisation a duré quatre ans.
[servlet] detailed explanation of servlet (use + principle)
一个月把字节,腾讯,阿里都面了,写点面经总结……
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Frame synchronization implementation
解决computed属性与input的blur事件冲突问题
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
First acquaintance with STL
冰冰学习笔记:一步一步带你实现顺序表