最近發現乙個** 力扣 檢視
上面有很多演算法和資料庫的題目,做了一下,發現自己平時都疏忽了,因此邊做邊記錄下來
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 |
+----+----------+
+------------+----------+--------+| department | employee | salary |
+------------+----------+--------+
| it | max | 90000 |
| sales | henry | 80000 |
+------------+----------+--------+
select d. name as department,e. name as employee,e.salary from department d,employee ewhere d.id = e.departmentid and (e.salary, e.departmentid) in (select max(salary),departmentid from employee group by departmentid)
部門工資最高的員工
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...
mysql 部門工資最高的員工(力扣)
sql架構 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 m...