Top earner per department

MediumWindow functionsHR analytics

The problem

For each department, show the highest-paid employee(s). Return dept_name, name and salary.

If two people tie for the top salary, show both. Employees with no department are excluded.

Tables · Company directory

Click a table or column name to insert it into your query.

  • INTEGER · primary key
  • TEXT
Sample rows (4 total)
Sample rows from departments
dept_iddept_name
1Engineering
2Analytics
3Sales
4HR

  • INTEGER · primary key
  • TEXT
  • INTEGER · → departments, can be NULL
  • INTEGER · → employees.emp_id, NULL for top managers
  • INTEGER · rupees per year
Sample rows (12 total)
Sample rows from employees
emp_idnamedept_idmanager_idsalary
1Anita Rao1NULL260000
2Bhavin Shah11180000
3Chitra Menon11180000
4Deepak Verma12140000
5Esha Gupta2NULL220000

Next: Visit → signup → purchase funnel →

Ctrl/⌘ + Enter runs the query. Table and column names are suggested as you type. Press Esc then Tab to leave the editor with the keyboard.

Expected output (3 rows)
Expected output
dept_namenamesalary
EngineeringAnita Rao260000
AnalyticsEsha Gupta220000
SalesImran Sheikh170000

Row order doesn’t matter for this question. Numbers are compared with a tiny tolerance; text must match exactly.

Stuck?

Stored on this device only. Your latest query and “solved” status are remembered in this browser only. They don’t sync between devices, and clearing your browser data removes them.