当前位置:网站首页>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
边栏推荐
- 全连接层的作用是什么?
- Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
- We reference My97DatePicker to realize the use of time plug-in
- OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
- Svn detailed use tutorial
- 冰冰学习笔记:一步一步带你实现顺序表
- 【Proteus仿真】自动量程(范围<10V)切换数字电压表
- Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
- 三、梯度下降求解最小θ
- AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
猜你喜欢
UML project example -- UML diagram description of tiktok
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
外包幹了四年,廢了...
一个月把字节,腾讯,阿里都面了,写点面经总结……
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
【Servlet】Servlet 详解(使用+原理)
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
eolink 如何助力远程办公
[servlet] detailed explanation of servlet (use + principle)
1N5408-ASEMI整流二极管1N5408
随机推荐
redis的五种数据类型
Detailed explanation of C language P2 selection branch statement
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
1-初识Go语言
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Branch statement of process control
LotusDB 设计与实现—1 基本概念
Progress in the treatment of depression
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
多语言通信基础 06 go实现grpc的四种数据流模式实现
Vscode Chinese plug-in doesn't work. Problem solving
Matrix exchange row and column
8.5 循环神经网络简洁实现
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)
ASEMI超快恢复二极管与肖特基二极管可以互换吗
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
Svn detailed use tutorial
A blog allows you to learn how to write markdown on vscode
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
We reference My97DatePicker to realize the use of time plug-in