Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Top 3 Salaries per Department | Ranking and Analytic Window Functions
Window Functions in SQL

bookChallenge: Top 3 Salaries per Department

Task

Swipe to start coding

Write a query to list the top 3 employees by salary in each department using a ranking window function.

  • Select the employee_id, name, department, and salary columns.
  • Use a ranking window function to assign a rank to each employee within their department, ordered by salary in descending order.
  • Return only those employees whose rank is 3 or less.
  • Order the results by department, then by salary descending, and then by name.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Top 3 Salaries per Department

Swipe to show menu

Task

Swipe to start coding

Write a query to list the top 3 employees by salary in each department using a ranking window function.

  • Select the employee_id, name, department, and salary columns.
  • Use a ranking window function to assign a rank to each employee within their department, ordered by salary in descending order.
  • Return only those employees whose rank is 3 or less.
  • Order the results by department, then by salary descending, and then by name.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

some-alt