2024年4月19日发(作者:)
平时的项目开发中,分页存储过程是用的比较多的存储过程,SqlServer分页存储过程
中经常要用到top,Oracle中则经常用到了RowNum.,mysql中常用到limit
现在,有一个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


发布评论