当前位置:网站首页>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
边栏推荐
- MySQL error packet out of order
- ArrayList collection basic usage
- 2-Go变量操作
- Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
- Sword finger offer II 019 Delete at most one character to get palindrome (simple)
- 你還不知道責任鏈模式的使用場景嗎?
- I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
- Epoll's et, lt working mode -- example program
- OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
- 如何打开Win10启动文件夹?
猜你喜欢
GIS数据处理-cesium中模型位置设置
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
Comment eolink facilite le télétravail
eolink 如何助力远程办公
Explain TCP's three handshakes in detail
Outsourcing for four years, abandoned
We reference My97DatePicker to realize the use of time plug-in
外包干了四年,废了...
LeetCode 练习——396. 旋转函数
随机推荐
【无标题】
LeetCode165-比较版本号-双指针-字符串
Programming philosophy - automatic loading, dependency injection and control inversion
Matrix exchange row and column
8.2 文本预处理
外包幹了四年,廢了...
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
8.3 语言模型与数据集
QT interface optimization: QT border removal and form rounding
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
帧同步 实现
Epolloneshot event of epoll -- instance program
epoll 的EPOLLONESHOT 事件———实例程序
Daily question - leetcode396 - rotation function - recursion
ASEMI三相整流桥和单相整流桥的详细对比
Bingbing learning notes: take you step by step to realize the sequence table
你還不知道責任鏈模式的使用場景嗎?
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
8.5 循环神经网络简洁实现