184. Department Highest Salary - 部门工资最高的员工 <Medium>

Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id。

+----+-------+--------+--------------+
| Id | Name  | Salary | DepartmentId |
+----+-------+--------+--------------+
| 1  | Joe   | 70000  | 1            |
| 2  | Jim   | 90000  | 1            |
| 3  | Henry | 80000  | 2            |
| 4  | Sam   | 60000  | 2            |
| 5  | Max   | 90000  | 1            |
+----+-------+--------+--------------+
Department 表包含公司所有部门的信息。

+----+----------+
| Id | Name     |
+----+----------+
| 1  | IT       |
| 2  | Sales    |
+----+----------+
编写一个 SQL 查询,找出每个部门工资最高的员工。对于上述表,您的 SQL 查询应返回以下行(行的顺序无关紧要)。

+------------+----------+--------+
| Department | Employee | Salary |
+------------+----------+--------+
| IT         | Max      | 90000  |
| IT         | Jim      | 90000  |
| Sales      | Henry    | 80000  |
+------------+----------+--------+
解释:

Max 和 Jim 在 IT 部门的工资都是最高的,Henry 在销售部的工资最高。

 

select b.Name as `Department`,a.Name as `Employee`,a.Salary
from Employee a 
left join Department b on b.Id = a.DepartmentId
where a.Salary in (
    select max(Salary) from Employee where DepartmentId = b.Id
)

or 

select b.name as `Department`,a.Name as `Employee`,a.Salary 
from Employee a, Department b 
where b.Id = a.DepartmentId and a.Salary in (
    select max(Salary) from Employee where DepartmentId = b.Id
)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<%@page pageEncoding="utf-8" %> <!-- Modal --> <div class="modal fade" id="registerModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title text-info">用户注册</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <form method="post" action="${pageContext.request.contextPath }/model/register"> <div class="modal-body"> <div class="form-group row"> <label class="col-sm-2 col-form-label">用户名</label> <div class="col-sm-10"> <input class="form-control" id="username" name="un" type="text" required /> <span class="text-danger" id="checkInfo"></span> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">密码</label> <div class="col-sm-10"> <input class="form-control" name="pw" type="password" required /> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">电话</label> <div class="col-sm-10"> <input class="form-control" name="tel" type="number" required /> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">地址</label> <div class="col-sm-10"> <input class="form-control" name="addr" type="text" required /> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button> <button type="submit" class="btn btn-primary" id="regButton">确定</button> </div> </form> </div> </div> </div>解析每一行代码
最新发布
06-13

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值