Sql
--Sqlserver分页查询语句 PageSize:每页显示几条数据 | PageIndex:当前页索引 | T为表 注:通常PageIndex索引从零开始 --效率最高 select ID,Name from T where ID in(
select top PageSize ID from(
select top ( (PageIndex+1)*PageSize) ID from T order by ID asc )
TT order by TT.ID desc)
order by T.ID asc --效率次之 select top PageSize * from T where ID not in( select top (PageIndex*PageSize) ID from T order by ID )
order by ID
--sql语句,取出表A中的第31条到40条记录(表A以自动增长的ID做主键,注意ID可能是不连续的
--事先删除了ID 为33的数据
--第一种
select top 10 ID from T where ID not in(select top 30 ID from T ORDER BY ID ASC)ORDER BY ID
--第二种
SELECT * FROM (select top 10 * FROM( select top 40 * from T order by ID asc)TT order by TT.ID DESC)TTT order by TTT.ID asc
--第三种
select * from T where T.ID in( select top 10 ID FROM(select top 40 ID from T order by T.ID asc)TT order by TT.ID desc) order by ID
--第四种
select * from( select ROW_NUMBER() over(order by ID)TT FROM T)TTT WHERE TTT.TT between 30 and 40