日期:2014-05-18  浏览次数:20466 次

怎么排除上次已查询过的值
SQL code

select  top  16  * from tbl_picinfo a  where a.[picid]>=( select max(b.[picid])  
from ( select  TOP 1  [picid]  from tbl_picinfo  where 1=1    ORDER BY [picid] )b)  and a.[picid] in (select min(picid)
[picid] from tbl_picinfo group by dcname,rcname)   ORDER BY a.[picid]

结果:
1
2
3
4
5
7
9
10
13
[color=#FF0000]
29
31
32
35
41
42
46
[/color]

select  top  16  * from tbl_picinfo a  where   a.[picid]>=( select max(b.[picid])  from ( select  TOP 17  
[picid]  from tbl_picinfo  where 1=1    
ORDER BY [picid] )b   )  and a.[picid] in (select min(picid) [picid] from tbl_picinfo group by dcname,rcname)   ORDER BY a.[picid]
 
[color=#FF0000]
29
31
32
35
41
42
46
[/color]
47
55
56
62
64
72
78
81
87




请问该怎么去掉上次已查询过的呢,我是用做分页!不能太慢,或者有什么更高效的查询,望指点!

------解决方案--------------------
做分页?
select *
from (
select id=row_number() over (order by getdate()),* from tb ) K
where id between 1 and 10
------解决方案--------------------
楼上的想的太多了
------解决方案--------------------
你的是sql 2000?
那就放到一个临时表中

select id=identity(int,1,1),* into #t from tb

然后
select * from #t where id between 1 and 10