We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。查询收入超过他们经理的员工的姓名
Id
create table employee ( id int, name varchar(255), salary int, managerId int ); insert into employee values (1, 'Joe', 70000, 3), (2, 'Henry', 80000, 4), (3, 'Sam', 60000, null), (4, 'Max', 90000, null);
select employee.name from employee left join employee e on employee.managerId = e.id where employee.salary > e.salary;
managerId 是经理 id ,同时经理也是员工,也就是说没有 managerId 是普通员工,有 managerId 的是经理。
managerId
id
所以将 employee 自连接,连接条件是 employee.managerId = e.id ,就可以把普通员工和经理连接起来了。
employee
employee.managerId = e.id
然后在筛选出 employee.salary > e.salary 的员工就行了。
employee.salary > e.salary
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的
Id
。查询收入超过他们经理的员工的姓名SQL
解析
managerId
是经理id
,同时经理也是员工,也就是说没有managerId
是普通员工,有managerId
的是经理。所以将
employee
自连接,连接条件是employee.managerId = e.id
,就可以把普通员工和经理连接起来了。然后在筛选出
employee.salary > e.salary
的员工就行了。The text was updated successfully, but these errors were encountered: