Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Row number question

Author  Topic 

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2015-04-18 : 17:16:26
Hello there.

I have a question with a row number. Below I have 2 columns that I want to
Put a row number with.

ID. Quantity DesiredRowNumber

123 1. 1
123. 1 1
123. 1. 1
123. 3 2
123. 3. 2
123. 4 3
123. 5 4
123. 5. 4
123. 7 5
123. 7. 5

789. 1 1
789. 1. 1
789. 3 2
789. 3. 2
789 4 3
789. 5 4
789. 5. 4
789. 7 5
789. 7. 5

How would I get the desired row number.

Many thanks.

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-04-18 : 18:54:48
[code]
select id, quantity
, rn = dense_Rank() over(partition by id order by quantity)
from table
[/code]
Go to Top of Page
   

- Advertisement -