[LeetCode-SQL-Easy]181. Employees Earning More Than Their Managers

問題:

The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

Id Name Salary ManagerId
1 Joe 70000 3
2 Henry 80000 4
3 Sam 60000 NULL
4 Max 90000 NULL

Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.

Employee
Joe

大意:
給定Employee表,請編寫一個SQL查詢,找出掙得比經理多的員工。從上表中可以看出,Joe是唯一一個收入超過經理的員工。
要求結果如上方。

解題

很簡單,熟悉使用where就能解

SELECT
    a.Name as Employee
FROM
    employee AS a,
    employee AS b
WHERE
    a.ManagerId=b.Id
        AND a.Salary > b.Salary
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,448評論 0 10
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,890評論 0 23
  • 本文轉載自知乎 作者:季子烏 筆記版權歸筆記作者所有 其中英文語句取自:英語流利說-懂你英語 ——————————...
    Danny_Edward閱讀 43,952評論 4 38
  • 今天又是熱鬧的一天。 上午你剛洗完澡,姐姐、弟弟們和舅舅來到,帶來了現在比較熱衷的野菜。 孩子從小很少接觸到,何況...
    可愛的寶閱讀 137評論 0 1
  • 那天聽過一節課,好像是講自控的一些事情,就是說失控是很正常的,就是那種自控力大人也只能掌控自己百分之四十,感覺我現...
    D023黎閱讀 169評論 1 1