日期:2014-05-18 浏览次数:20730 次
create table tb(a int, b int, c int, d int)
insert into tb values(1, 1, 1, 1)
insert into tb values(1, 2, 1, 1)
insert into tb values(2, 2, 1, 2)
insert into tb values(3, 3, 1, 1)
insert into tb values(3, 1, 2, 1)
go
select * , re=(select count(1) from tb where a=t.a and (c<t.c or (c=t.c and b<t.b)) )+1 from tb t
drop table tb
/*
a b c d re
----------- ----------- ----------- ----------- -----------
1 1 1 1 1
1 2 1 1 2
2 2 1 2 1
3 3 1 1 1
3 1 2 1 2
(所影响的行数为 5 行)
*/