当前位置:网站首页>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
边栏推荐
- SQLSERVER事物与锁的问题
- Alexnet model
- Resolve the conflict between computed attribute and input blur event
- Model location setting in GIS data processing -cesium
- GIS数据处理-cesium中模型位置设置
- Want to be an architect? Tamping the foundation is the most important
- 外包干了四年,废了...
- 2-Go变量操作
- OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
- L'externalisation a duré quatre ans.
猜你喜欢
随机推荐
Leetcode153 - find the minimum value in the rotation sort array - array - binary search
Daily question - leetcode396 - rotation function - recursion
8.5 循环神经网络简洁实现
Thread synchronization, life cycle
Outsourcing for four years, abandoned
[servlet] detailed explanation of servlet (use + principle)
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
Contraction mapping theorem
想要成为架构师?夯实基础最重要
Svn detailed use tutorial
Branch statement of process control
[NLP] HMM hidden Markov + Viterbi word segmentation
压缩映射定理
你还不知道责任链模式的使用场景吗?
thinkphp5+数据大屏展示效果
GIS数据处理-cesium中模型位置设置
全连接层的作用是什么?
[detailed explanation of factory mode] factory method mode
Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time