You want only the top-2 earners per department from a ROW_NUMBER query. Why must the filter go in an outer query rather than the WHERE clause of the same SELECT?
SELECT * FROM (
SELECT name, dept,
ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC) AS rn
FROM emp
) t
WHERE rn <= 2;