当前位置:网站首页>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
)
边栏推荐
- What are the projects of metauniverse and what are the companies of metauniverse
- Digital twin smart factory develops digital twin factory solutions
- Installing redis under Linux
- Codeforces Round #771 (Div. 2)---A-D
- Go basic data type
- Many to one, one to many processing
- Unique line of "Gelu"
- I've been interviewed. The starting salary is 16K
- Pytorch里面多任务Loss是加起来还是分别backward?
- MySQL Foundation
猜你喜欢
How to apply for company email when registering in company email format?
基于OpenCV实现口罩识别
[shutter] shutter open source project reference
容器运行时分析
实用系列丨免费可商用视频素材库
Realization of mask recognition based on OpenCV
CDN acceleration requires the domain name to be filed first
Dishes launcher small green program and directory management (efficiency tool)
Convolution和Batch normalization的融合
Pytorch里面多任务Loss是加起来还是分别backward?
随机推荐
leetcode 650. 2 keys keyboard with only two keys (medium)
Sourcetree details
开源了 | 文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
Where is the win11 automatic shutdown setting? Two methods of setting automatic shutdown in win11
Agnosticism and practice makes perfect
Digital twin smart factory develops digital twin factory solutions
Container runtime analysis
Where is the win11 microphone test? Win11 method of testing microphone
Load balancing cluster (LBC)
vim区间删行注释
Mapper代理开发
Data set - fault diagnosis: various data and data description of bearings of Western Reserve University
[analysis of STL source code] imitation function (to be supplemented)
基于FPGA的VGA协议实现
[shutter] shutter open source project reference
判断二叉树是否为满二叉树
【ML】李宏毅三:梯度下降&分类(高斯分布)
Leetcode DP three step problem
How to maintain the brand influence of clothing enterprises
How does win11 turn on visual control? Win11 method of turning on visual control