LeetCode DB: Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.
+----+-------+--------+--------------+
| Id | Name | S
alary | DepartmentId |
+----+-------+--------+--------------+
| 1 | Joe | 70000 | 1 |
| 2 | Henry | 80000 | 2 |
| 3 | Sam | 60000 | 2 |
| 4 | Max | 90000 | 1 |
+----+-------+--------+--------------+
The Department table holds all departments of the company.
+----+----------+
| Id | Name |
+----+----------+
| 1 | IT |
| 2 | Sales |
+----+----------+
Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, Max has the highest salary in the IT department and Henry has the highest salary in the Sales department.
+------------+----------+--------+
| Department | Employee | Salary |
+------------+----------+--------+
| IT | Max | 90000 |
| Sales | Henry | 80000 |
+------------+----------+--------+
考察怎么做groupby和join吧
select D.name as Department, E.Name as Employee, E.Salary from Employee as E
INNER JOIN
(select DepartmentId as did, max(Salary) as sal from Employee group by DepartmentId) T
ON E.Salary = T.sal and E.DepartmentId = T.did
INNER JOIN
Department AS D
ON D.Id = T.did
LeetCode DB: Department Highest Salary的更多相关文章
- [LeetCode#184]Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)
一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...
- [LeetCode] Department Highest Salary -- 数据库知识(mysql)
184. Department Highest Salary The Employee table holds all employees. Every employee has an Id, a s ...
- [LeetCode] Department Highest Salary 系里最高薪水
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- LeetCode——Department Highest Salary(花式使用IN以及GROUP BY)
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- [SQL]LeetCode184. 部门工资最高的员工 | Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- LeetCode 176 Second Highest Salary mysql,select 嵌套 难度:1
https://leetcode.com/problems/second-highest-salary/ Write a SQL query to get the second highest sal ...
- 【SQL】184. Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- LeetCode 177. Nth Highest Salary
https://leetcode.com/problems/nth-highest-salary/description/ Write a SQL query to get the nth highe ...
随机推荐
- Git-根据tag创建分支
有时候需要根据tag创建分支. 现在主分支上有一个tag为vtest.1.0.FINAL,主分支的名字为master. 1.执行:git origin fetch 获得最新. 2.通过:git bra ...
- cas未能够识别出目标 ***;票根
使用cas做单点登录,在验证ticket的时候,报下面的错误: <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> & ...
- OC中双向链表的实现
双向链表的概念 双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和直接前驱.所以,从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点.一般我们都 ...
- [原创]K8_C段旁注查询工具5.0 30款国外主流CMS识别+智能识别未知CMS
8_C段旁注查询工具V5.0 20161214作者:K8拉登哥哥 唯一QQ:396890445平台: Windows + .NET Framework 4.0 简介:K8_C段 提供4种方式查询子域名 ...
- 02-01 Java关键字、标识符、注释、常量和进制问题、变量和数据类型
1:关键字 (1)被Java语言赋予特定含义的单词 (2)特点: 全部小写. (3)注意事项: A:goto和const作为保留字存在. B:类似于Notepad++这样的高级记事本会对关键字有特殊颜 ...
- vue教程2-07 微博评论功能
vue教程2-07 微博评论功能 <!doctype html> <html> <head> <meta charset="utf-8"& ...
- web工程迁移---weblogic8迁移到jboss5遇到的异常
原有的web工程是在weblogic8上运行的,但现在的要求是要运行到jboss5中,为如后迁移到更高版本的jboss做准备 由于我对weblogic没有过研究,所以之前的步骤都是有别人进行的,在进行 ...
- 单线程实现同时监听多个端口(windows平台c++代码)
前言 多年前开发了一套网络库,底层实现采用IOCP(完成端口).该库已在公司多个程序中应用:经过多次修改,长时间检验,已经非常稳定高效. 最近把以前的代码梳理了一下,又加进了一些新的思路.代码结构更加 ...
- mysql5.7主从复制配置——读写分离实现
为什么使用主从架构?1.实现服务器负载均衡:2.通过复制实现数据的异地备份:3.提高数据库系统的可用性:4.可以分库[垂直拆分],分表[水平拆分]: 主从配置的前提条件1.MySQL版本一致:2.My ...
- zmq 自动绑定socket
def auto_bind(socket): """ auto bind zmq socket :param socket: socket instance :retur ...