欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 平时的项目开发中,分页存储过程是用的比较多的存储过程,SqlServer分页存储过程中经常要用到top,Oracle中则经常用到了RowNum. 现在,有一个UserInfo表,一个字段是UserId,另一个字段是UserName,其中
欢迎进入oracle社区论坛,与200万技术人员互动交流 >>进入
平时的项目开发中,分页存储过程是用的比较多的存储过程,SqlServer分页存储过程中经常要用到top,Oracle中则经常用到了RowNum.
现在,有一个UserInfo表,一个字段是UserId,另一个字段是UserName,其中是UserId是自动增长的,步长是1.表中共有30条数据,其中UserId的值不一定是连续的。现在要实现的目的是取其中的第11至第20条记录。先看SqlServer的几种做法:
第一种写法:
select top 10 *
from UserInfo
where UserId in
(
select top 20 UserId
from UserInfo
)
order by UserId desc

第二种写法:
select top 10 * from UserInfo where UserId not in
(select top 10 UserId from UserInfo )

第三种写法:
select top 10 * from UserInfo where UserId>
(select max(UserId) from
(select top10 UserId from UserInfo order by UserId) a)

第四种写法(只可在Sqlserver 2005中):
select * from (select Row_Number() over
(Order by UserId) as RowId ,* from UserInfo) U
where U.RowId between 10 and 20

[1] [2]

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号