Skip to content

1875. Group Employees of the Same Salary 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
WITH
  EmployeesWithCountPerSalary AS (
    SELECT
      *,
      COUNT(employee_id) OVER(PARTITION BY salary) AS count_per_salary
    FROM Employees
  )
SELECT
  employee_id,
  name,
  salary,
  DENSE_RANK() OVER(ORDER BY salary) AS team_id
FROM EmployeesWithCountPerSalary
WHERE count_per_salary > 1
ORDER BY team_id, employee_id;