employee 表包含所有員工,他們的經理也屬於員工。每個員工都有乙個 id,此外還有一列對應員工的經理的 id。
+
----+-------+--------+-----------+
| id | name | salary | managerid |
+----+-------+--------+-----------+|1
| joe |
70000|3
||2| henry |
80000|4
||3| sam |
60000
|null||
4| max |
90000
|null|+
----+-------+--------+-----------+
給定 employee 表,編寫乙個 sql 查詢,該查詢可以獲取收入超過他們經理的員工的姓名。在上面的**中,joe是唯一乙個收入超過他的經理的員工。
+
----------+
| employee |
+----------+
| joe |
+----------+
首先查出屬性只為員工的人員
select
*from employee where managerid is
notnull
然後再以經理的id左連線員工表
select a.name as employee from
(select
*from employee where managerid is
notnull
)as a left
join employee b on a.managerid=b.id
再加上條件員工的工資比經理的工資要大即為結果
select a.name as employee from
(select
*from employee where managerid is
notnull
)as a left
join employee b on a.managerid=b.id where a.salary>b.salary;
LeetCode 181 超過經理收入的員工 解題
超過經理收入的員工 employee 表包含所有員工,他們的經理也屬於員工。每個員工都有乙個 id,此外還有一列對應員工的經理的 id。id name salary managerid 1 joe 70000 3 2 henry 80000 4 3 sam 60000 null 4 max 9000...
LeetCode 181 超過經理輸入的員工
題目 employee 表包含所有員工,他們的經理也屬於員工。每個員工都有乙個 id,此外還有一列對應員工的經理的 id。id name salary managerid 1 joe 70000 3 2 henry 80000 4 3 sam 60000 null 4 max 90000 null ...
LeetCode181超過經理收入的員工
題目 employee 表包含所有員工,他們的經理也屬於員工。每個員工都有乙個 id,此外還有一列對應員工的經理的 id。id name salary managerid 1 joe 70000 3 2 henry 80000 4 3 sam 60000 null 4 max 90000 null ...