当前位置:网站首页>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
边栏推荐
- 1-初识Go语言
- 2-GO variable operation
- GIS数据处理-cesium中模型位置设置
- Swift - literal, literal protocol, conversion between basic data types and dictionary / array
- QT actual combat: Yunxi calendar
- 3、 Gradient descent solution θ
- 1n5408-asemi rectifier diode
- Leetcode162 - find peak - dichotomy - array
- SVN详细使用教程
- Don't you know the usage scenario of the responsibility chain model?
猜你喜欢

电容

机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏

Leetcode153 - find the minimum value in the rotation sort array - array - binary search
![Detailed explanation of C language knowledge points -- first knowledge of C language [1]](/img/7d/2fc527949562e1a7ef1525c7fced81.png)
Detailed explanation of C language knowledge points -- first knowledge of C language [1]

A blog allows you to learn how to write markdown on vscode

Branch statement of process control

Arduino for esp8266串口功能简介

【工厂模式详解】工厂方法模式

利用 MATLAB 编程实现最速下降法求解无约束最优化问题

I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
随机推荐
自动化的艺术
vscode中文插件不生效问题解决
SQLSERVER事物与锁的问题
全连接层的作用是什么?
中富金石财富班29800效果如何?与专业投资者同行让投资更简单
2-GO variable operation
ASEMI整流模块MDQ100-16在智能开关电源中的作用
Epolloneshot event of epoll -- instance program
Model location setting in GIS data processing -cesium
压缩映射定理
Epoll's et, lt working mode -- example program
QT Detailed explanation of pro file
Svn detailed use tutorial
UML项目实例——抖音的UML图描述
UML project example -- UML diagram description of tiktok
Daily question - leetcode396 - rotation function - recursion
[NLP] HMM hidden Markov + Viterbi word segmentation
8.2 文本预处理
QT actual combat: Yunxi chat room
【NLP】HMM隐马尔可夫+维特比分词