当前位置:网站首页>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
边栏推荐
- 想要成为架构师?夯实基础最重要
- Explain TCP's three handshakes in detail
- pnpm安装使用
- What is the main purpose of PCIe X1 slot?
- Detailed explanation of C language knowledge points -- first knowledge of C language [1]
- Model location setting in GIS data processing -cesium
- Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
- 【JZ46 把数字翻译成字符串】
- Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
- Realization of four data flow modes of grpc based on Multilingual Communication
猜你喜欢
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
Thread synchronization, life cycle
一个月把字节,腾讯,阿里都面了,写点面经总结……
A blog allows you to learn how to write markdown on vscode
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
3、 Gradient descent solution θ
Branch statement of process control
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
随机推荐
[servlet] detailed explanation of servlet (use + principle)
Model location setting in GIS data processing -cesium
数组模拟队列进阶版本——环形队列(真正意义上的排队)
raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
解决computed属性与input的blur事件冲突问题
vscode中文插件不生效问题解决
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
Bingbing learning notes: take you step by step to realize the sequence table
epoll 的EPOLLONESHOT 事件———实例程序
async void 导致程序崩溃
八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
一款不错的工具:aardio
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
Contraction mapping theorem
MySQL报错packet out of order
51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
Master in minutes --- ternary operator (ternary operator)
qt之.pro文件详解