Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

85
Views
SQL RANK but higher if equal?

For data:

20
50
50
60
70

If I use RANK I get

1
2
2
4
5

if I use DENSE_RANK I get

1
2
2
3
4

I need for my application this:

1
3
3
4
5
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think you want:

rank() over(order by val) + count(*) over(partition by val) - 1

Actually this would be simpler phrased with just a window count:

count(*) over(order by val)

Demo on DB Fiddle:

select val, count(*) over(order by val) rn
from (values (20), (50), (50), (60), (70)) as t(val)
order by val
val | rn
--: | -:
 20 |  1
 50 |  3
 50 |  3
 60 |  4
 70 |  5
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!