[LeetCode]-DataBase-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 | Salary | 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 |
+------------+----------+--------+ 需求:查询每个部门工资最高的员工
CREATE TABLE Employee(
Id TINYINT UNSIGNED,
Name VARCHAR(20),
Salary DECIMAL(10,2),
DepartmentId TINYINT
)ENGINE=MyISAM CHARSET=utf8;
CREATE TABLE Department(
Id TINYINT UNSIGNED,
Name VARCHAR(20)
)ENGINE=MyISAM CHARSET=utf8;
SELECT b.nm,a.Name,a.salary
FROM employee a INNER JOIN (
SELECT t2.Id,t2.Name nm,MAX(t1.salary) sal
FROM employee t1 INNER JOIN department t2 ON t1.DepartmentId=t2.Id
GROUP BY t1.DepartmentId
)b ON a.salary=b.sal AND a.DepartmentId=b.Id
[LeetCode]-DataBase-Department Highest Salary的更多相关文章
- LeetCode DB: Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- [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 ...
随机推荐
- Linux FTP的安装与权限配置
ftp安装部分,操作步骤如下: 1.切换到root用户 2.查看是否安装vsftp,我这个是已经安装的. [root@localhost vsftpd]# rpm -qa |grep vsftpd v ...
- 094、Swarm 中最重要的概念(Swarm01)
参考https://www.cnblogs.com/CloudMan6/p/7845365.html 从主机层面来看,Docker Swarm 管理的是 Docker Host 集群.所以先来讨论 ...
- Python 常用库(随时补充)
1. Python-RSA使用手册 英文文档见Python-RSA使用手册,主要介绍了Python-RSA的消息的加密解密.文件的加密解密以及签名的方法. Installation 使用pip ins ...
- httpClient4.5.2工具类总结
使用背景: 因项目使用非结构化存储,http相关jar包统一升级到httpClient4.5.2,查阅相关文档总结如下,以咨分享,望不吝指教. 依赖jar包 httpclient-4.5.2.jar. ...
- 一、JS基本基础
一.主流编辑器 早期 atom 前几年sublime 小巧,轻量,功能插件较多: webstorm 集成开发环境 vscode 免费开源的. 运行环境 : 浏览器端 谷歌,IE,fi ...
- 在docker容器中为elasticsearch配置跨域访问
一.在docker容器中进入elasticsearch对应的容器 docker exec -it [容器名] /bin/bash 二.安装vim编辑器 因为我们需要更改配置文件,安装过的朋友就不用安装 ...
- Solr IK分词器配置
下载地址:https://search.maven.org/search?q=com.github.magese 分词器配置: 参考:https://www.cnblogs.com/mengjinlu ...
- 新手的Linux zcat命令示例
Zcat是一个命令行实用程序,用于查看压缩文件的内容.它将压缩文件扩展为标准输出,允许您查看内容. 分类:Linux命令操作系统 2018-08-13 00:00:00 通常,使用gzip压缩的文件可 ...
- Big Data(八)MapReduce的搭建和初步使用
---恢复内容开始--- 回顾: 1.最终开发MR的计算程序 2.hadoop 2.x 出现了一个yarn:资源管理>>MR没有后台场服务 yarn模型:container 容器,里面会运 ...
- 【gin-vue-admin】 使用go和vue 快速搭建一个项目模板
gin-vue-admin gin+vue开源快速项目模板 项目地址:https://github.com/piexlmax/gin-vue-admin 增加了 micro-service-test分 ...