读取指定的记录数

本文介绍了几种使用SQL进行升序查询的方法,包括基于计数的升序查询、使用row_number()函数实现的升序查询以及直接利用ID进行升序排列等。这些方法可以帮助开发者更灵活地处理数据排序需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 /*第一种 升序*/

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)

转载于:https://www.cnblogs.com/ruonanxiao/archive/2010/07/16/1779022.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值