您的位置:首页 > 运维架构

leetcode185 Department Top Three Salaries

2017-09-04 00:41 288 查看
Employee表存储员工姓名、员工所在公寓、员工工资

Department表存储公寓id

评选出各个公寓的工资前三名的员工。

遇到的问题如下:

limit,in等语句不能用在嵌套select语句中,多封装一层就可以了

select子句如何访问外部的关系表,虽然可以直接访问外面第一层的,但是无法访问外面第二层的

select dep.name as Department,
who.name as Employee,
who.salary as Salary
from
department as dep ,employee as who
where dep.id=who.departmentid
and 2>=( select count(1) from (
select distinct salary,departmentid from employee
)as dep_salary
where salary>who.salary and dep_salary.departmentid=dep.id
)
order by Salary desc;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: