必须先生成一个连续的ID才行.

解决方案 »

  1.   

    例如:按cnt从小到大。--sql 2000
    select * , px = (select count(1) from tb where cnt < t.cnt) + 1 from tb t--sql 2005
    select * , px = row_number() over(order by cnt) from tb然后对上面的查询做子查询来查。
    --sql 2000
    select * from
    (
      select * , px = (select count(1) from tb where cnt < t.cnt) + 1 from tb t
    ) m 
    where px = 1 --2,3,4--sql 2005
    select * from 
    (
      select * , px = row_number() over(order by cnt) from tb
    ) m
    where px = 1 --2,3,4