declare @SQLStr varchar(8000)
set @SQLStr='SELECT Top '+cast(@每页大小 as varchar)+' * FROM 表 WHERE num NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' num from 表 )'
exec(@SQLStr)
set @SQLStr='SELECT Top '+cast(@每页大小 as varchar)+' * FROM 表 WHERE num NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' num from 表 )'
exec(@SQLStr)
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable order by 排序字段
select top M-N * from #temptable where iid>=N
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable order by 排序字段
select top M-N * from #temptable where iid>=N
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable order by 排序字段
select top M-N * from #temptable where iid>=N
如果一共有102条记录,每页10条,查询第11页,应该得到的是2条记录啊,但用你的方法会得到10条哦,to CrazyFor(太阳下山明朝依旧爬上来):
如果说本身table就是一个临时表,而且数据量非常大,这样再建一个临时表是不可取的吧,我想要的就是不建临时表的情况下怎么解决这样的问题。
我想如果用大力的方法,实现是可以,就是要计算一下应该取top几,是这样吗?