当前位置:网站首页>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
边栏推荐
- ASEMI整流模块MDQ100-16在智能开关电源中的作用
- DVWA之暴力破解(Brute Force)Low-->high
- redis的五种数据类型
- We reference My97DatePicker to realize the use of time plug-in
- 【Proteus仿真】自动量程(范围<10V)切换数字电压表
- Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
- Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
- do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
- Unity_代码方式添加绑定按钮点击事件
- eolink 如何助力远程办公
猜你喜欢

1 - first knowledge of go language

OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示

redis的五种数据类型

Thread synchronization, life cycle

What is the main purpose of PCIe X1 slot?

Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)

《JVM系列》 第七章 -- 字节码执行引擎

Parameter stack pressing problem of C language in structure parameter transmission

MDS55-16-ASEMI整流模块MDS55-16

Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
随机推荐
帧同步 实现
eolink 如何助力远程办公
Don't you know the usage scenario of the responsibility chain model?
UML project example -- UML diagram description of tiktok
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
电容
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
Some little records~
8.5 循环神经网络简洁实现
Contraction mapping theorem
Logical volume creation and expansion
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
[NLP] HMM hidden Markov + Viterbi word segmentation
Epoll's et, lt working mode -- example program
epoll 的 ET,LT工作模式———实例程序
Programming philosophy - automatic loading, dependency injection and control inversion
基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
抑郁症治疗的进展