Pertama, Anda harus mendapatkan gaji maksimum untuk setiap departemen:
SELECT department, max(salary) as max_salary
FROM test
GROUP BY department
maka Anda dapat menggabungkan kembali subquery ini ke tabel pengujian:
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