当前位置:网站首页>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
)
边栏推荐
- 67 page overall planning and construction plan for a new smart city (download attached)
- ArrayList analysis 2: pits in ITR, listiterator, and sublist
- Fudian bank completes the digital upgrade | oceanbase database helps to layout the distributed architecture of the middle office
- Practical series - free commercial video material library
- 开源了 | 文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
- JDBC练习案例
- Connexion à distance de la tarte aux framboises en mode visionneur VNC
- What can I do after buying a domain name?
- Codeforces Round #771 (Div. 2)---A-D
- Load balancing cluster (LBC)
猜你喜欢

Many to one, one to many processing

Data set - fault diagnosis: various data and data description of bearings of Western Reserve University

Matlab 信号处理【问答笔记-1】

CADD课程学习(4)-- 获取没有晶体结构的蛋白(SWISS-Model)

Interpretation of new plug-ins | how to enhance authentication capability with forward auth

C MVC creates a view to get rid of the influence of layout

What experience is there only one test in the company? Listen to what they say

Connexion à distance de la tarte aux framboises en mode visionneur VNC

Mapper代理开发

Container runtime analysis
随机推荐
基于OpenCV实现口罩识别
leetcode 650. 2 Keys Keyboard 只有两个键的键盘(中等)
Container runtime analysis
MySQL Foundation
Installing redis under Linux
Intranet penetration | teach you how to conduct intranet penetration hand in hand
Writing of head and bottom components of non routing components
可知论与熟能生巧
How to maintain the brand influence of clothing enterprises
程序分析与优化 - 9 附录 XLA的缓冲区指派
95页智慧教育解决方案2022
Sourcetree details
Open source | Wenxin big model Ernie tiny lightweight technology, which is accurate and fast, and the effect is fully open
S12. Verify multi host SSH mutual access script based on key
The privatization deployment of SaaS services is the most efficient | cloud efficiency engineer points north
RuntimeError: no valid convolution algorithms available in CuDNN
CDN acceleration requires the domain name to be filed first
[live broadcast appointment] database obcp certification comprehensive upgrade open class
[array] binary search
Agnosticism and practice makes perfect