当前位置:网站首页>The difference between having and where in SQL
The difference between having and where in SQL
2022-04-23 14:50:00 【Jan_ ssen】
stay SQL in , General addition, deletion, query and modification statements use WHERE Keywords to retrieve special fields , But when SELECT Used in query statements GROUP BY For grouping queries , For conditional filtering of grouped results, you need HAVING key word .
Simply speaking , Namely WHERE Used before grouping ,HAVING Used after grouping !
for example , Find the average score of classes with class number less than four
SELECT class, AVG(score)
FROM test
WHERE class<4
GROUP BY class;
SELECT class, AVG(score)
FROM test
GROUP BY class
HAVING class<4;
Both of the above expressions are correct , But the former is to filter first and then group , The latter is to group first and then filter .
Of course , This example is just one by one , In many cases, you must filter the grouped data , that HAVING It'll come in handy .
版权声明
本文为[Jan_ ssen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231446553533.html
边栏推荐
猜你喜欢
随机推荐
[servlet] detailed explanation of servlet (use + principle)
三、梯度下降求解最小θ
ArrayList collection basic usage
PCIe X1 插槽的主要用途是什么?
thinkphp5+数据大屏展示效果
eolink 如何助力遠程辦公
Go basic reflection
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
The art of automation
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
1n5408-asemi rectifier diode
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
ASEMI整流模块MDQ100-16在智能开关电源中的作用
Detailed explanation of C language P2 selection branch statement
First acquaintance with STL
[jz46 translate numbers into strings]
你还不知道责任链模式的使用场景吗?
Is asemi ultrafast recovery diode interchangeable with Schottky diode
pnpm安装使用