select COUNT(*) from table where id <= 3
/*
-----------
2
*/select COUNT(*) from table where id <= 13
/*
-----------
5
*/
/*
-----------
2
*/select COUNT(*) from table where id <= 13
/*
-----------
5
*/
调试欢乐多
楼主忘了加order by .
insert into tb select 1,'a'
insert into tb select 3,'b'
insert into tb select 10,'c'
insert into tb select 11,'d'
insert into tb select 13,'e'
insert into tb select 15,'f'select px = (select count(1) from tb where [id] < T.[id])+1,* from tb Tdrop table tb/*
px id text
1 1 a
2 3 b
3 10 c
4 11 d
5 13 e
6 15 f*/