Først skal du få den maksimale løn for hver afdeling:
SELECT department, max(salary) as max_salary
FROM test
GROUP BY department
så kan du slutte denne underforespørgsel tilbage til testtabellen:
SELECT t.*
FROM
test t INNER JOIN (
SELECT department, max(salary) as max_salary
FROM test
GROUP BY department
) d ON t.department=d.department AND t.salary=d.max_salary