Find the bugs: Highest-paid employees in each department

Find the highest-paid employees in each department. If two employees share the highest salary, both must appear in the result. Exclude employees who have no assigned department or whose salary is missing. Find the lines containing errors.

Find the errorsDuplicates and top NMiddleAnalystData Engineer
Input data · iv_employees
idnamedepartment_idmanager_idsalaryhired_at
1Anna1NULL5000.002020-03-01 09:00:00
2Boris115000.002021-06-15 09:00:00
3Clara114000.002022-01-31 23:59:00
4Dmitry216000.002019-09-01 09:00:00
5Elena245500.002021-02-01 00:00:00
6Foma245500.002023-04-10 10:30:00
7Galina314500.002020-11-20 09:00:00
8HugoNULL13000.002024-05-05 09:00:00
9Irina37NULL2024-08-12 09:00:00
10Egor243500.002025-01-13 09:00:00
SELECT department_id, name, salary
FROM (
  SELECT department_id, name, salary,
         ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS pos
  FROM iv_employees
  WHERE department_id IS NOT NULL
    AND salary IS NOT NULL
) t
WHERE pos = 1
ORDER BY department_id, name