In SQL Server, I am trying to get the top 5 salaries.
I have salaries like
5000
5000
4500
4500
3000
2000
1000
500
400
and I’d like to get
5000
5000
4500
4500
3000
2000
1000
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to get the top 5 distinct salaries (no matter how many times the same amount might show up), you need to use the
DENSE_RANK()ranking function and a CTE to achieve this:This results in an output like this: