求分页sql(sqlserver)
表名是参数,页索引2个参数的情况下 怎么进行分页
------解决方案--------------------
select ceiling(2.1)
----方法1:
WITH UserInfos AS
(
select *,row_number() over(order by user_id) as RowNumber
from user_info
)
select *
from UserInfos
where RowNumber between 21 and 30
----方法2:
select * from
(
select *,row_number() over(order by user_id desc) as RowNumber
from user_info
) A
where RowNumber between 21 and 30
----方法3:
select top 10 * from user_info
where user_id not in
(
select top 20 user_id from user_info
order by user_id
)
order by user_id
----方法4:
SELECT TOP 10 *
FROM user_info
WHERE (user_id >
(SELECT MAX(user_id)
FROM (SELECT TOP 20 user_id
FROM user_info
ORDER BY user_id) AS T))
ORDER BY user_id
----方法5:
select *
from
(
select top 10 *
from
(
select top 30 *
from user_info
order by user_id
) A
order by user_id desc
) B
order by user_id