iT邦幫忙

0

leetcode with MySQL:181. Employees Earning More Than Their Managers

  • 分享至 

  • xImage
  •  

題目:

Table: Employee

+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
| salary | int |
| managerId | int |
+-------------+---------+
id is the primary key column for this table.
Each row of this table indicates the ID of an employee, their name, salary, and the ID of their manager.

Write an SQL query to find the employees who earn more than their managers.

Return the result table in any order.

給定一個table,找到薪水比他們經理高的人

SELECT a.Name AS Employee
FROM Employee AS a JOIN Employee AS b
ON a.ManagerId = b.Id
AND a.Salary > b.Salary;

將該表(a表)跟另一個自己(b表)結合
條件設a表ManagerId等於b表的Id且a表的Salary大於b表的Salary
然後把a表的name選出就好
最後執行時間319ms(faster than 92.73%)

那我們下題見


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言