AdventureWorks Database: Return the top ten employees ranked by their salary
SQL Query - AdventureWorks: Exercise-117 with Solution
117. From the following table write a query in SQL to return the top ten employees ranked by their salary.
Sample table: HumanResources.EmployeePayHistory
Sample Solution:
SELECT BusinessEntityID, Rate,
DENSE_RANK() OVER (ORDER BY Rate DESC) AS RankBySalary
FROM HumanResources.EmployeePayHistory
FETCH FIRST 10 ROWS ONLY;
Sample Output:
businessentityid|rate |rankbysalary| ----------------+-------+------------+ 1| 125.5| 1| 25|84.1346| 2| 273|72.1154| 3| 2|63.4615| 4| 234|60.0962| 5| 263|50.4808| 6| 7|50.4808| 6| 234|48.5577| 7| 287| 48.101| 8| 274| 48.101| 8|
SQL AdventureWorks Editor:
Practice Online
Contribute your code and comments through Disqus.
Previous: Rank the products by the specified inventory locations.
Next: Divide rows into defined groups based on SalesYTD.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join