当前位置:网站首页>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)
- 判断二叉树是否为满二叉树
- Analyze ad654: Marketing Analytics
- MFC file operation
- Where is the win11 microphone test? Win11 method of testing microphone
- JSON数据传递参数
- Open Source | Wenxin Big Model Ernie Tiny Lightweight Technology, Accurate and Fast, full Open Effect
- sourcetree 详细
- 2022 latest and complete interview questions for software testing
- vim区间删行注释
猜你喜欢

95 pages of smart education solutions 2022

【ML】李宏毅三:梯度下降&分类(高斯分布)
![[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)](/img/c5/2f65d37682607aab98443d7f1ba775.jpg)
[shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)

带角度的检测框 | 校准的深度特征用于目标检测(附实现源码)

Mapper agent development

PR FAQ, what about PR preview video card?

開源了 | 文心大模型ERNIE-Tiny輕量化技術,又准又快,效果全開

Where is the win11 automatic shutdown setting? Two methods of setting automatic shutdown in win11

JDBC练习案例

采用VNC Viewer方式远程连接树莓派
随机推荐
Where is the win11 microphone test? Win11 method of testing microphone
Judge whether the binary tree is full binary tree
MATLAB signal processing [Q & a notes-1]
Happy Lantern Festival, how many of these technical lantern riddles can you guess correctly?
直击产业落地!飞桨重磅推出业界首个模型选型工具
What is the official website address of e-mail? Explanation of the login entry of the official website address of enterprise e-mail
Explain in detail the process of realizing Chinese text classification by CNN
Interface switching based on pyqt5 toolbar button -2
Data set - fault diagnosis: various data and data description of bearings of Western Reserve University
Digital twin visualization solution digital twin visualization 3D platform
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
The privatization deployment of SaaS services is the most efficient | cloud efficiency engineer points north
JDBC practice cases
一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)
[live broadcast appointment] database obcp certification comprehensive upgrade open class
接口自动化覆盖率统计——Jacoco使用
顶级 DevOps 工具链大盘点
JDBC tutorial
VIM interval deletion note
判断二叉树是否为满二叉树