以下查询,
declare @data as TABLE (one int, two int);
insert into @data (one, two) values (1,1)
insert into @data (one, two) values (2,1)
insert into @data (one, two) values (3,2)
insert into @data (one, two) values (4,2)
insert into @data (one, two) values (5,2)
insert into @data (one, two) values (6,1)
insert into @data (one, two) values (7,1)
insert into @data (one, two) values (8,3)
insert into @data (one, two) values (9,3)
select one, two,
dense_rank() OVER (ORDER BY two ASC) AS BlockNumber --Same dates same number
from @data
order by one
结果,
one two BlockNumber
1 1 1
2 1 1
3 2 2
4 2 2
5 2 2
6 1 1
7 1 1
8 3 3
9 3 3
但是,我想要以下结果,
one two BlockNumber
1 1 1
2 1 1
3 2 2
4 2 2
5 2 2
6 1 3**
7 1 3**
8 3 4**
9 3 4**
有什么建议么?