I post analytics questions daily. Check today's question.Try it now
MS
Mathew Shem Verified

Find the Top 3 Highest Paid Employees per Department

20mediumSQLwindow-functionsrankinggroup-by

You have a table called employees with these columns:

  • employee_id

  • name

  • department

  • salary

Write a SQL query that returns the top 3 highest paid employees in each department. Show the department, employee name and salary, ordered by department and then by salary from highest to lowest.

If two employees in the same department have the same salary, explain how your query handles the tie.

Also tell me in one or two sentences why you chose your approach, for example a window function versus a subquery.