( SELECT em.Id Id,em.Name Name,em.Salary Salary,em.DepartmentId dep
FROM Employee em
WHERE (
#count records whose salary large than outer salary
SELECT count(1) FROM Employee emp
WHERE em.DepartmentId=emp.DepartmentId
And em.Salary
)<=2) temp
#for record with highest salary, 0 record large than it; for record with second highest #salary, 1 record large than it. To get top three, records large than target record should #<=2
WHERE temp.dep=d.Id
ORDER BY Department ,Salary DESC;
#in this way, as ‘count’ does not remove duplicate records, there will be a gap after #records with same salary