题目
https://leetcode.cn/problems/department-top-three-salaries/description/
# 部门工资前三高的所有员工
# 1.最外层的表
#select as Department, as Employee, as Salary from xxx where ;
# 2.工资比谁高, 需要有个比较的对象,相同的表用2次进行比较.
## 工资前三高, 意味着 比 e1.salary 高的数量只能是 0, 1, 2个
# (select count(distinct e2.name) from Employee e2 where e2.salary > e1.salary) < 3
# 3.每个部门, 意味着工资比较是在同一部门内, 此时 e1和e2保证部门id 一样
# (select count(distinct e2.name) from Employee e2 where e2.salary > e1.salary and e1.departmentId = e2.departmentId) < 3
# 注意 count(distinct e2.name) 改为 count(distinct e2.salary) 是钱的前三,同样的钱算一个名次
# 4.输出结果
select d.name as Department,e1.name as Employee, e1.salary as Salary from Employee e1 left join Department d on e1.departmentId = d.id
where
(select count(distinct e2.salary) from Employee e2 where e2.salary > e1.salary and e1.departmentId = e2.departmentId) < 3 ;
```