RANK() window function
Intuition\nuse rank() to rank salary partition by departments, then select rank = 1 rows\n\n# Code\n\n/* Write your T-SQL query statement below */\nWITH joined 
# Intuition\nuse rank() to rank salary partition by departments, then select rank = 1 rows\n\n# Code\n```\n/* Write your T-SQL query statement below */\nWITH joined as(\nSELECT d.name Department,\ne.name as Employee, \ne.salary as Salary,\nRANK() over (PARTITION BY d.name ORDER BY e.salary DESC) rank \nFROM Department d \nJOIN Employee e on d.id = e.departmentId\n) \n\nselect \nDepartment,Employee, Salary\nfrom joined \nWHERE rank = 1\n\n\n```
['MS SQL Server']