当前位置:网站首页>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
边栏推荐
- UML项目实例——抖音的UML图描述
- [NLP] HMM hidden Markov + Viterbi word segmentation
- 【无标题】
- 交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
- 1 - first knowledge of go language
- Parameter stack pressing problem of C language in structure parameter transmission
- Master in minutes --- ternary operator (ternary operator)
- Find daffodils - for loop practice
- 编程哲学——自动加载、依赖注入与控制反转
- Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
猜你喜欢

Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Progress in the treatment of depression

一个月把字节,腾讯,阿里都面了,写点面经总结……

一款不错的工具:aardio

Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"

基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】

Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code

金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)

I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
随机推荐
自动化的艺术
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
Usage of BC
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
QT actual combat: Yunxi chat room
你还不知道责任链模式的使用场景吗?
Vscode Chinese plug-in doesn't work. Problem solving
抑郁症治疗的进展
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
多语言通信基础 06 go实现grpc的四种数据流模式实现
The initial C language framework is suitable for review and preliminary understanding
2-GO variable operation
Svn detailed use tutorial
Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data