value1 value2 COL3
----------- -----------
1 12 1
1 13 2
1 23 3
0 14 1
0 15 2
1 16 1
0 23 1
0 22 2
1 21 1
1 12 2 就实现COL3这种排序。请问大侠们col3这列排序是怎么排的?问题来源:ID:SQL77 发的帖子 http://topic.csdn.net/u/20090804/21/3832e1bb-db00-4d88-b99c-1b78c067bb84.html
----------- -----------
1 12 1
1 13 2
1 23 3
0 14 1
0 15 2
1 16 1
0 23 1
0 22 2
1 21 1
1 12 2 就实现COL3这种排序。请问大侠们col3这列排序是怎么排的?问题来源:ID:SQL77 发的帖子 http://topic.csdn.net/u/20090804/21/3832e1bb-db00-4d88-b99c-1b78c067bb84.html
select
value1,value2,
col3=(
select
count(1)
from
#
where
[value1]=a.[value1]
and
id<=a.id
and
id>=(select isnull(max(id),0) from # where id<a.id and value1!=a.value1))
from
# a