读取指定的记录数

我要第一条,第二条,第三条,

 /*第一种 升序*/

select top 1 * from table_A  where  (select count(1) from table_A where ID<= T.ID)  > 2


select top 1  rn= (select count(1) from table_A where ID<= T.ID), * from table_A  where  (select count(1) from table_A where ID<= T.ID)  > 2

 

 /*第二种 升序*/

select row_number()  over( order by  ID)  as  row_number, *   from  table_A

 

select top 1 t.ID,t.Name from (select t.ID,t.Name,row_number() over(order by ID) rn from table_A ) as t where rn >2(第三条) 

/*第三种 ID顺序asc 升序*/

select top 1 * from table_A where ID not in (select top 1 ID from table_A)

 /*第四种   ID倒叙 desc 降序*/

 select * from table_A where id =(select  min(t.id) as id from
(select top 3 id from  table_A order by id desc) as t)

posted on 2010-07-16 16:19  ruonanxiao  阅读(352)  评论(5编辑  收藏  举报

导航