当前位置:网站首页>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
)
边栏推荐
- Bean加载控制
- [shutter] shutter photo wall (center component | wrap component | clickrrect component | stack component | positioned component | button combination component)
- 【OJ】两个数组的交集(set、哈希映射 ...)
- Solution to boost library link error
- SharedPreferences save list < bean > to local and solve com google. gson. internal. Linkedtreemap cannot be cast to exception
- Where is the win11 automatic shutdown setting? Two methods of setting automatic shutdown in win11
- Difference between NVIDIA n card and amda card
- JDBC练习案例
- 【STL源码剖析】仿函数(待补充)
- How can cross-border e-commerce achieve low-cost and steady growth by laying a good data base
猜你喜欢
Digital twin visualization solution digital twin visualization 3D platform
Open Source | Wenxin Big Model Ernie Tiny Lightweight Technology, Accurate and Fast, full Open Effect
Mapper代理开发
容器运行时分析
Explain in detail the process of realizing Chinese text classification by CNN
CADD course learning (4) -- obtaining proteins without crystal structure (Swiss model)
Three solutions to frequent sticking and no response of explorer in win11 system
Interface switching based on pyqt5 toolbar button -1
Difference between NVIDIA n card and amda card
Ideal car × Oceanbase: when the new forces of car building meet the new forces of database
随机推荐
95页智慧教育解决方案2022
What is the official website address of e-mail? Explanation of the login entry of the official website address of enterprise e-mail
Use of cocospods
CDN acceleration requires the domain name to be filed first
Where is the win11 automatic shutdown setting? Two methods of setting automatic shutdown in win11
[analysis of STL source code] imitation function (to be supplemented)
Bean加载控制
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
How to maintain the brand influence of clothing enterprises
Interface difference test - diffy tool
ArrayList analysis 2: pits in ITR, listiterator, and sublist
What can I do after buying a domain name?
Program analysis and Optimization - 9 appendix XLA buffer assignment
Use redis to realize self increment serial number
带角度的检测框 | 校准的深度特征用于目标检测(附实现源码)
Happy Lantern Festival, how many of these technical lantern riddles can you guess correctly?
Implementation of VGA protocol based on FPGA
How can cross-border e-commerce achieve low-cost and steady growth by laying a good data base
Mapper agent development
Returns the root node of the largest binary search subtree in a binary tree