employee
表包含所有員工資訊,每個員工有其對應的 id, salary 和 department id。
+----+-------+--------+--------------+| id | name | salary | departmentid |
+----+-------+--------+--------------+
| 1 | joe | 70000 | 1 |
| 2 | henry | 80000 | 2 |
| 3 | sam | 60000 | 2 |
| 4 | max | 90000 | 1 |
+----+-------+--------+--------------+
department
表包含公司所有部門的資訊。
+----+----------+編寫乙個 sql 查詢,找出每個部門工資最高的員工。例如,根據上述給定的**,max 在 it 部門有最高工資,henry 在 sales 部門有最高工資。| id | name |
+----+----------+
| 1 | it |
| 2 | sales |
+----+----------+
+------------+----------+--------+select d.name as department,e.name as employee,e.salary from employee e left join department d on e.departmentid=d.id where d.id is not null and (e.departmentid,e.salary) in (select departmentid,max(salary) from employee group by departmentid ) order by e.salary asc;| department | employee | salary |
+------------+----------+--------+
| it | max | 90000 |
| sales | henry | 80000 |
+------------+----------+--------+
部門工資最高的員工
employee表包含所有員工資訊,每個員工有其對應的 id,salary 和 department id。id name salary departmentid 1 joe 70000 1 2 henry 80000 2 3 sam 60000 2 4 max 90000 1 department...
部門工資最高的員工
leecode的題目。關於in的應用。感覺很經典,這裡列出解題過程。employee 表包含所有員工資訊,每個員工有其對應的 id,salary 和 department id。sql如下 set names utf8mb4 set foreign key checks 0 table struct...
Q200510 01 求部門工資最高的員工
問題 求部門工資最高的員工 employee 表包含所有員工資訊,每個員工有其對應的 id,salary 和 department id。id name salary departmentid 1 joe 70000 1 2 henry 80000 2 3 sam 60000 2 4 max 900...