select COUNT(*) from table where id <= 3
/*
-----------
2
*/select COUNT(*) from table where id <= 13
/*
-----------
5
*/

解决方案 »

  1.   

    select count(id) from table where id<=3 order by id ascselect count(id) from table where id<=13 order by id asc
    楼主忘了加order by .
      

  2.   

    --这样?create table tb([id] int,[text] varchar(5))
    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*/