i have a field which name is “account” and its varchar type,this field have data that can repeat or can only apear once, i need that other field called “consecutive” counts how many times does the data in “account” apears, i can't do it manually because i have lots of data.
This is an example of what i have
Account Consecutive
24590 1
24590 1
23789 1
23789 1
23789 1
98789 1
98789 1
89768 1
89768 1
15678 1
15678 1
14356 1
This is what i need Account Consecutive
24590 1
24590 2
23789 1
23789 2
23789 3
98789 1
We don't have much to work with here but pretty sure you need something along these lines. (This of course assumes that you are using sql-server)
select Account
, Consecutive = ROW_NUMBER() over (partition by Account, order by (select null))
from SomeTable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.