See if in my example below meets your need:
create table #temp (doc int,cliente int)
insert into #temp
values
('10','15')
,('10','15')
,('10','15')
,('23','59')
,('23','59')
,('23','59')
select *
, ROW_NUMBER () OVER (PARTITION BY doc ORDER BY doc ASC) as Parcela
, ROW_NUMBER() OVER (ORDER BY doc) AS 'Row Number'
, RANK() OVER ( ORDER BY doc ) AS 'Rank'
, DENSE_RANK() OVER ( ORDER BY doc ) AS 'Dense Rank'
, NTILE(4) OVER ( ORDER BY doc ) AS 'Quartile'
from #temp
Upshot:
doc |cliente|Parcela |Row Number |Rank |Dense Rank |Quartile
10 |15 |1 |1 |1 |1 |1
10 |15 |2 |2 |1 |1 |1
10 |15 |3 |3 |1 |1 |1
23 |59 |1 |4 |4 |2 |2
23 |59 |2 |5 |4 |2 |2
23 |59 |3 |6 |4 |2 |2
A brief explanation about Ranking functions:
ROW_NUMBER () OVER ([ <partition_by_clause>] <order_by_clause>)
Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row on each partition.
RANK () OVER ([ <partition_by_clause>] <order_by_clause>) ([RANK () OVER <partition_by_clause>] <order_by_clause>)
Returns (Rank) the position of each row within the partition of a result set.
DENSE_RANK () OVER ([ <partition_by_clause>] <order_by_clause>) ([DENSE_RANK () OVER <partition_by_clause>] <order_by_clause>)
Returns (Rank) the position of rows within the partition of a result set without any gaps in the ranking.
NTILE (integer_expression) OVER ([ <partition_by_clause>] <order_by_clause>)
Distributes the rows of an ordered partition into a certain number of groups.
Wow! Sorry for the delay in answering Ricardo. A great explanation. You can be sure that I will write everything down here, because I know that I will need it in the future. Very detailed and well explained. Really fight.
– Giovane Barbosa