Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Highest Paid Employee per Department | Subqueries in Human Resources
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Subqueries in SQL

bookChallenge: Highest Paid Employee per Department

In a typical Human Resources database, you may be asked to find the highest paid employee in each department. This is a common scenario where subqueries are invaluable: you need to compare each employee’s salary within their department and return only those who earn the most. The challenge is to write a query that, for every department, identifies the top earner by salary. You have access to the departments and employees tables, where each employee is linked to a department and has a salary value. Your goal is to use subqueries to determine the highest paid employee for each department.

Uppgift

Swipe to start coding

Write a query to find the highest paid employee in each department. For each department, return the department name, the employee’s name, and their salary.

  • Use a subquery to determine the maximum salary within each department.
  • Return only those employees whose salary matches the highest salary in their department.
  • Include the department name, employee name, and salary in the results.
  • Sort the results by department name and then by employee name.

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 6
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you show me an example SQL query for this scenario?

What columns are available in the `departments` and `employees` tables?

How would the query change if there are ties for the highest salary in a department?

close

bookChallenge: Highest Paid Employee per Department

Svep för att visa menyn

In a typical Human Resources database, you may be asked to find the highest paid employee in each department. This is a common scenario where subqueries are invaluable: you need to compare each employee’s salary within their department and return only those who earn the most. The challenge is to write a query that, for every department, identifies the top earner by salary. You have access to the departments and employees tables, where each employee is linked to a department and has a salary value. Your goal is to use subqueries to determine the highest paid employee for each department.

Uppgift

Swipe to start coding

Write a query to find the highest paid employee in each department. For each department, return the department name, the employee’s name, and their salary.

  • Use a subquery to determine the maximum salary within each department.
  • Return only those employees whose salary matches the highest salary in their department.
  • Include the department name, employee name, and salary in the results.
  • Sort the results by department name and then by employee name.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 6
single

single

some-alt