0

Is there a way to write a row_number() function such that the column below titled (HELP HERE) can be achieved? I want to be able to rank columns a through d into buckets per the data in column d.

a b c d (HELP HERE) 1603 82 117276 36 1 1603 82 117276 36 1 1603 82 117276 37 2 1603 82 117276 37 2

If I try row_number() over (partition by a,b,c order by d) the data reacts like this

a b c d (HELP HERE) 1603 82 117276 36 1 1603 82 117276 36 2 1603 82 117276 37 1 1603 82 117276 37 2

William Robertson
  • 15,273
  • 4
  • 38
  • 44
am340
  • 29
  • 1
  • 6
  • 1
    `rank()` or `dense_rank()` window function ought to do it. Here's an SO question explaining the difference: https://stackoverflow.com/questions/11183572/whats-the-difference-between-rank-and-dense-rank-functions-in-oracle – Tom O. Oct 12 '17 at 16:56
  • ?? If you try row_number() like you show, the HELP HERE column will have values 1, 2, 3, 4 - not 1, 2, 1, 2 as you show. –  Oct 12 '17 at 19:28

1 Answers1

3

try dense_rank() over (order by d)

ltt
  • 417
  • 3
  • 12