LeetCode資料庫題 超過經理收入的員工

2021-09-27 01:37:25 字數 796 閱讀 8544

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 name as employee from employee as e, (select distinct id, salary from employee) as m where e.managerid = m.id and e.salary > m.salary

LeetCode刷題 資料庫

目錄 175.組合兩個表 176.第二高的薪水 表1 person 列名 型別 personid int firstname varchar lastname varchar personid 是上表主鍵表2 address 列名 型別 addressid int personid int city...

LeetCode資料庫題 有趣的電影

某城市開了一家新的電影院,吸引了很多人過來看電影。該電影院特別注意使用者體驗,專門有個 led顯示板做電影推薦,上面公布著影評和相關電影描述。作為該電影院的資訊部主管,您需要編寫乙個 sql查詢,找出所有影片描述為非 boring 不無聊 的並且 id 為奇數 的影片,結果請按等級 rating 排...

oracle資料庫in 超過1000 的解決方案

專案中遇到sql語句的in超過1000這個問題,再次總結一下解決方案 使用動態拼接sql語句in or in 效能太差,再次不多說 使用表代替in中的字串,事務問題 由2引申出使用oracle的臨時表,使用臨時表,想怎麼查怎麼查。該問題中,本人用的是事務臨時表 在這詳細說一下,臨時表 oracle的...