Skip to main content

Top Salaries by Department

Hard

Given the database with the schema shown below, write a SQL query to fetch the top earning employee by department, ordered by department name.

employees projects +---------------+---------+ +---------------+---------+ | id | int |<----+ +->| id | int | | first_name | varchar | | | | title | varchar | | last_name | varchar | | | | start_date | date | | salary | int | | | | end_date | date | | department_id | int |--+ | | | budget | int | +---------------+---------+ | | | +---------------+---------+ | | | departments | | | employees_projects +---------------+---------+ | | | +---------------+---------+ | id | int |<-+ | +--| project_id | int | | name | varchar | +-----| employee_id | int | +---------------+---------+ +---------------+---------+

Your query should return a result in the following format:

department_name | employee_id | first_name | last_name | salary ----------------+-------------+------------+-----------+-------- varchar | int | varchar | varchar | int