美文网首页
[LeetCode-SQL-Easy]181. Employe

[LeetCode-SQL-Easy]181. Employe

作者: AceCream佳 | 来源:发表于2019-04-08 15:06 被阅读0次

问题:

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

相关文章

网友评论

      本文标题:[LeetCode-SQL-Easy]181. Employe

      本文链接:https://www.haomeiwen.com/subject/xeauiqtx.html