当前位置:网站首页>Several methods of the minimum value in the maximum value of group query
Several methods of the minimum value in the maximum value of group query
2022-07-02 23:57:00 【Mu code text】
Several methods of grouping and querying the minimum value of the maximum value
give an example : Query the lowest department in the highest salary of each department
This question is a bit tongue twisty , Breaking it down is to find out the maximum salary of each department , Then find out which department has the lowest salary
This involves sub queries , There are several ways to do this
The way 1:
You can find out the maximum salary of each department , Then sort in positive order , Take the first one
# The way 1
SELECT MAX(salary)
FROM employees
GROUP BY department_id
ORDER BY MAX(salary)
LIMIT 1;
The way 2:
You can first calculate the maximum salary of each department , Then find the smallest value
# The way 2
SELECT MIN(max_sal)
FROM (
SELECT MAX(salary) max_sal
FROM employees
GROUP BY department_id
) t
The way 3:
Find out the maximum salary of each department , Get any result less than or equal to the result set according to the result
# The way 3
SELECT department_id, MAX(salary)
FROM employees
GROUP BY department_id
HAVING MAX(salary)<=ALL( -- All values less than the result ,ANY For any one of
SELECT MAX(salary) max_sal
FROM employees
GROUP BY department_id
)
边栏推荐
- [ml] Li Hongyi III: gradient descent & Classification (Gaussian distribution)
- JDBC Exercise case
- Create an interactive experience of popular games, and learn about the real-time voice of paileyun unity
- 接口差异测试——Diffy工具
- [array] binary search
- Pytorch里面多任务Loss是加起来还是分别backward?
- 返回二叉树中最大的二叉搜索子树的大小
- Top Devops tool chain inventory
- MFC gets the current time
- 流媒体技术优化
猜你喜欢

Three solutions to frequent sticking and no response of explorer in win11 system

35页危化品安全管理平台解决方案2022版

PR FAQ, what about PR preview video card?

Optimization of streaming media technology

JDBC practice cases

直击产业落地!飞桨重磅推出业界首个模型选型工具

Writing of head and bottom components of non routing components
![[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)](/img/93/dc940caebe176177e4323317ebf4fa.jpg)
[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)
![[analysis of STL source code] imitation function (to be supplemented)](/img/40/a02a04a24f385a31e0484d1071ecec.jpg)
[analysis of STL source code] imitation function (to be supplemented)

CADD课程学习(4)-- 获取没有晶体结构的蛋白(SWISS-Model)
随机推荐
Connexion à distance de la tarte aux framboises en mode visionneur VNC
Develop knowledge points
A single element in an ordered array -- Valentine's Day mental problems
JDBC Exercise case
接口差异测试——Diffy工具
Improvement of RTP receiving and sending PS stream tool (II)
All things work together, and I will review oceanbase's practice in government and enterprise industry
The privatization deployment of SaaS services is the most efficient | cloud efficiency engineer points north
Use of cocospods
流媒体技术优化
Fudian bank completes the digital upgrade | oceanbase database helps to layout the distributed architecture of the middle office
Implementation of VGA protocol based on FPGA
Convolution和Batch normalization的融合
開源了 | 文心大模型ERNIE-Tiny輕量化技術,又准又快,效果全開
What can I do after buying a domain name?
Wechat applet basic learning (wxss)
Request and response
How does win11 turn on visual control? Win11 method of turning on visual control
Matlab 信号处理【问答笔记-1】
一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)