当前位置: 首页 > article >正文

Leecode SQL 184. Department Highest Salary 找出tie

  1. Department Highest Salary

注意!要找出 tie 的 highest salary!

Write a solution to find employees who have the highest salary in each of the departments.

Return the result table in any order.

The result format is in the following example.

Input
Employee =

idnamesalarydepartmentId
1Joe700001
2Jim900001
3Henry800002
4Sam600002
5Max900001

Department =

idname
1IT
2Sales

Output

DepartmentEmployeesalary
ITJim90000
SalesHenry80000
ITMax90000

My wrong solution (didn’t find the tie):

-- WITH a AS (
--     SELECT departmentId AS di, name, MAX(salary) AS highest
--     FROM employee e
--     GROUP BY e.departmentId
-- )

-- SELECT d.name AS Department, a.name AS Employee, a.highest AS Salary
-- FROM a
--     JOIN department d
--         ON a.di = d.id

Correct solution by others:

SELECT dp.name AS Department, em.name AS Employee, em.salary
FROM Employee AS em 
    JOIN Department as dp 
        ON em.departmentId = dp.id 
WHERE em.salary = (SELECT MAX(salary) FROM Employee 
				WHERE departmentId = dp.id )

http://www.kler.cn/news/331183.html

相关文章:

  • 基于STM32的数字温度传感器设计与实现
  • 测试面试题:请你分别介绍一下单元测试、集成测试、系统测试、验收测试、回归测试
  • 影响 Linux、Unix 系统的 CUPS 漏洞可导致 RCE
  • Spring Boot与观察者模式实现数据同步更新机制
  • vue访问组件的数据和方法
  • 移情别恋c++ ദ്ദി˶ー̀֊ー́ ) ——13.mapset(模拟实现)
  • 33. java快速排序
  • 探索Python新境界:funboost库揭秘
  • `git fetch` 检查更新
  • Unity2017在安卓下获取GPS位置时闪退的解决办法
  • Windows64的nasm汇编详细教程,不是DOS!
  • 分布式选举 - Paxos 协议选举过程详解
  • 宠物饮水机的水箱低液位提醒如何实现?
  • CMU 10423 Generative AI:lec18(大模型的分布式训练)
  • 【Linux 进程】进程的状态管理
  • kubernetes-强制删除命名空间
  • 力扣9.30
  • linux-阻塞IO与非阻塞IO
  • Why RTSP?RTSP播放器优势探究
  • 在pycharm中设置后直接运行js代码