184. 部门工资最高的员工

 

184. 部门工资最高的员工

需要注意的几个点,inner join可以缩减成join,取的是两个表的交集

in关键词,找的是当前所要找的数值是否在指定的范围之中

# Write your MySQL query statement below
select d.Name as Department,
       e.Name as Employee,
       e.Salary
       from Employee e inner join Department d on e.DepartmentId = d.Id
       where (DepartmentId, e.Salary)
       in
       (select DepartmentId, max(Salary) from Employee group by DepartmentId);    

 

这个是有问题的版本,暂时还不知道怎么改,只是提示group by使用错误

# Write your MySQL query statement below select d.Name as Department, e1.Name as Employee, max(e1.Salary) as Salary from Employee e1, Employee e2, Department d where e1.Salary >= max(e2.Salary) and e1.DepartmentId = e2.DepartmentId group by e1.Id order by e1.Salary desc; 

 

原文地址:https://www.cnblogs.com/letlifestop/p/12516614.html

时间: 2024-08-30 12:21:14

184. 部门工资最高的员工的相关文章

SQL练习——查询部门工资最高的员工

题目来源于leetcode:184. 部门工资最高的员工 思路: 首先是分部门的,因此肯定会用到group by ;其次各部门拥有最高工资的员工可能不仅仅只有一个人. 初步解法: 根据需求,可以先查询Employee表中的各部门的最高工资标准,作为一个标准线,代码如下: select Max(Salary) Salary,DepartmentId from Employee group by Employee.DepartmentId -- 各部门最高工资的标准  有了这个工资水平线,就可以用它

MySQL_项目7: 各部门工资最高的员工(难度:中等)

项目七: 各部门工资最高的员工(难度:中等) 创建Employee 表,包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id. +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+-------+--------+--------------+ | 1 | Joe | 70000 | 1 | | 2 | Henry | 80000 | 2 | |

力扣——部门工资前三高的员工(数据库的题

Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id . +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+-------+--------+--------------+ | 1 | Joe | 70000 | 1 | | 2 | Henry | 80000 | 2 | | 3 | Sam | 60000 | 2 | |

为什么企业宁愿开高工资给新员工,都不愿意给老员工加工资?

有朋友问到: 俺的建议: 先从这位被低薪压制的老员工角度说说: 决定你的薪资水平的根本原因是你的实力,而影响因素是你的性格.为什么说是你的性格呢?比方说你比较好欺负,不好意思和老板提要求,老板就会继续低薪用你,最多每年加你一点点.你作为老员工和老板谈工资,你的筹码比较弱,因为你需要保住这份工. 老板招聘新员工就不同了,老板需要这个岗位才去招聘的,有必要的话,他会出他能接受范围内的最高工资的. 所以从这位老员工的角度看来,自己就被欺负了,感觉自己实力比新员工还好,为啥我的待遇低? 当然这些都是自我

数据库笔试——查出各部门超出部门平均薪资的员工的姓名,薪资,所在部门名称及部门平均薪水

有一段时间没做数据库的题了,前面面试偶然做到这么一题目,觉得不错,凭记忆将题目记下来,然后在数据库中实现了一遍. 题目大概是这样: 一张员工表 employee,包含字段 id,name,salary,dep_no; 一张部门信息表 department,包含字段 id,dep_no,name,其中 employee 的 dep_no 关联 department 的 dep_no;写 sql 查出各部门超出部门平均薪资的员工的姓名,薪资,所在部门名称及部门平均薪水. 下面是我创建的两张表: DR

部门中薪资超过部门平均薪资的员工姓名及薪资

部门中薪资超过部门平均薪资的员工姓名及薪资 # 题表 # 建表 create table emp( id int not null unique auto_increment, name varchar(20) not null, sex enum('male','female') not null default 'male', #大部分是男的 age int(3) unsigned not null default 28, hire_date date not null, post varc

leetcode185 部门工资前三高的所有员工 Department Top Three Salaries

Employee 表包含所有员工信息,每个员工有对应的 Id,此外还有一列部门 Id. 创建表和数据: Create table If Not Exists Employee (Idint, Name varchar(255), Salary int, DepartmentId int); Create table If Not Exists Department (Idint, Name varchar(255)); Truncate table Employee; insert into E

2018-07-25期 MapReduce求部门工资总和及平均工资

1.Mapper类 package cn.sjq.bigdata.mr.salary; import java.io.IOException; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; /** * 求部门员工薪资总和

校区下部门 及校区下员工

该校区下所有员工select * from employee eINNER JOIN employee_department ed on e.id =ed.EmployeeIdLEFT JOIN department d on d.Id= ed.DepartmentIdwhere e.IsDeleted=0#未删除and e.State=1#在职and FIND_IN_SET('355',d.Path)#校区id GROUP BY e.id; 校区下部门