濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫(kù) > SQL實(shí)現(xiàn)LeetCode(181.員工掙得比經(jīng)理多)

SQL實(shí)現(xiàn)LeetCode(181.員工掙得比經(jīng)理多)

熱門標(biāo)簽:云南電商智能外呼系統(tǒng)價(jià)格 高清地圖標(biāo)注道路 臨清電話機(jī)器人 拉卡拉外呼系統(tǒng) 智能外呼系統(tǒng)復(fù)位 外東北地圖標(biāo)注 400電話可以辦理嗎 大眾點(diǎn)評(píng)星級(jí)酒店地圖標(biāo)注 話務(wù)外呼系統(tǒng)怎么樣

[LeetCode] 181.Employees Earning More Than Their Managers 員工掙得比經(jīng)理多

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      |
+----------+

這道題給我們了一個(gè)Employee表,里面有員工的薪水信息和其經(jīng)理的信息,經(jīng)理也屬于員工,其經(jīng)理Id為空,讓我們找出薪水比其經(jīng)理高的員工,那么就是一個(gè)很簡(jiǎn)單的比較問題了,我們可以生成兩個(gè)實(shí)例對(duì)象進(jìn)行內(nèi)交通過ManagerId和Id,然后限制條件是一個(gè)Salary大于另一個(gè)即可:

解法一:

SELECT e1.Name FROM Employee e1
JOIN Employee e2 ON e1.ManagerId = e2.Id
WHERE e1.Salary > e2.Salary;

我們也可以不用Join,直接把條件都寫到where里也行:

解法二:

SELECT e1.Name FROM Employee e1, Employee e2
WHERE e1.ManagerId = e2.Id AND e1.Salary > e2.Salary;

參考資料:

https://leetcode.com/discuss/88189/two-straightforward-way-using-where-and-join

到此這篇關(guān)于SQL實(shí)現(xiàn)LeetCode(181.員工掙得比經(jīng)理多)的文章就介紹到這了,更多相關(guān)SQL實(shí)現(xiàn)員工掙得比經(jīng)理多內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • SQL實(shí)現(xiàn)LeetCode(196.刪除重復(fù)郵箱)
  • SQL實(shí)現(xiàn)LeetCode(185.系里前三高薪水)
  • SQL實(shí)現(xiàn)LeetCode(184.系里最高薪水)
  • SQL實(shí)現(xiàn)LeetCode(183.從未下單訂購(gòu)的顧客)
  • SQL實(shí)現(xiàn)LeetCode(182.重復(fù)的郵箱)
  • SQL實(shí)現(xiàn)LeetCode(180.連續(xù)的數(shù)字)
  • C++實(shí)現(xiàn)LeetCode(179.最大組合數(shù))
  • SQL實(shí)現(xiàn)LeetCode(197.上升溫度)

標(biāo)簽:無錫 福州 阿里 定西 揚(yáng)州 山西 三明 溫州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SQL實(shí)現(xiàn)LeetCode(181.員工掙得比經(jīng)理多)》,本文關(guān)鍵詞  SQL,實(shí)現(xiàn),LeetCode,181.,員工,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《SQL實(shí)現(xiàn)LeetCode(181.員工掙得比經(jīng)理多)》相關(guān)的同類信息!
  • 本頁收集關(guān)于SQL實(shí)現(xiàn)LeetCode(181.員工掙得比經(jīng)理多)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    鹤岗市| 平和县| 宁蒗| 潮州市| 阳泉市| 安徽省| 方城县| 山东| 新化县| 南投市| 赤水市| 东丽区| 射阳县| 芮城县| 东阳市| 澜沧| 成安县| 加查县| 霍城县| 台中市| 扎兰屯市| 宝兴县| 内丘县| 昌乐县| 邳州市| 咸丰县| 灵石县| 东乡县| 南部县| 七台河市| 巴东县| 双峰县| 乡宁县| 宜宾县| 大渡口区| 大埔县| 芦溪县| 加查县| 南岸区| 青冈县| 治多县|