https://leetcode.com/problems/department-top-three-salaries/description/

 

Department Top Three Salaries - LeetCode

Department Top Three Salaries - Table: Employee +--------------+---------+ | Column Name | Type | +--------------+---------+ | id | int | | name | varchar | | salary | int | | departmentId | int | +--------------+---------+ id is the primary key column for

leetcode.com

 

sql문제는 어려워...

 

같은부서에 속하는 사람들중 나보다 더 큰 사람들의 월급의 distinct 개수가 3개 미만인 것만 뽑으면 된다.

select d.name as 'Department', e.name as 'Employee', e.salary as 'Salary'
from Employee e
join Department d
on e.departmentId = d.id
where 3 > (select count(distinct(e2.salary))
                from Employee e2
                where e2.salary > e.salary
                and e.departmentId = e2.departmentId)

물론 말이쉽지 나도 보고했다.

+ Recent posts