博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode - 185. Department Top Three Salaries
阅读量:6410 次
发布时间:2019-06-23

本文共 1500 字,大约阅读时间需要 5 分钟。

The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id.

+----+-------+--------+--------------+| Id | Name  | Salary | DepartmentId |+----+-------+--------+--------------+| 1  | Joe   | 70000  | 1            || 2  | Henry | 80000  | 2            || 3  | Sam   | 60000  | 2            || 4  | Max   | 90000  | 1            || 5  | Janet | 69000  | 1            || 6  | Randy | 85000  | 1            |+----+-------+--------+--------------+

The Department table holds all departments of the company.

+----+----------+| Id | Name     |+----+----------+| 1  | IT       || 2  | Sales    |+----+----------+

Write a SQL query to find employees who earn the top three salaries in each of the department. For the above tables, your SQL query should return the following rows.

+------------+----------+--------+| Department | Employee | Salary |+------------+----------+--------+| IT         | Max      | 90000  || IT         | Randy    | 85000  || IT         | Joe      | 70000  || Sales      | Henry    | 80000  || Sales      | Sam      | 60000  |+------------+----------+--------+
# Write your MySQL query statement belowSELECT    d.`Name` AS Department,    e1. NAME AS Employee,    e1.SalaryFROM    employee e1 JOIN    department d ON e1.DepartmentId=d.IdWHERE    3 > (        SELECT            COUNT(DISTINCT Salary)        FROM            employee e2        WHERE            e2.Salary > e1.Salary        AND e1.DepartmentId = e2.DepartmentId    )

 

转载地址:http://rizra.baihongyu.com/

你可能感兴趣的文章
给大家讲解一下JavaScript与后台Java天衣无缝相结合
查看>>
探索HTML5之本地文件系统API - File System API
查看>>
javascript有用代码块(1)
查看>>
libevent 笔记
查看>>
PHP实现人人OAuth登录和API调用
查看>>
redis源码笔记 - initServer
查看>>
FindBugs工具常见问题
查看>>
ECSHOP报错误Deprecated: preg_replace(): The /e modifier is depr
查看>>
【iOS】iOS之Button segue弹出popOver消除(dismiss)问题
查看>>
java多线程系列5-死锁与线程间通信
查看>>
数据库分库分表
查看>>
腾讯Hermes设计概要——数据分析用的是列存储,词典文件前缀压缩,倒排文件递增id、变长压缩、依然是跳表-本质是lucene啊...
查看>>
小程序模板嵌套以及相关遍历数据绑定
查看>>
Systemd入门教程:命令篇(转)
查看>>
java随机范围内的日期
查看>>
linux包之diff
查看>>
spring事务学习(转账案例)(二)
查看>>
[官方教程] [ES4封装教程]1.使用 VMware Player 创建适合封装的虚拟机
查看>>
http协议与http代理
查看>>
【iOS开发-91】GCD的同步异步串行并行、NSOperation和NSOperationQueue一级用dispatch_once实现单例...
查看>>