select top 20 id from table where id not in(select top 40 id from table order by time) order by time
解决方案 »
- 新手用sql 2005的迷惑
- 如何知道某表是否有触发器?有几种方法?
- if select t from sys > Getdate()
- 求一SQL语句,关于两个点的差值,自己写了一句,感觉不对,特请教!具体见内!谢谢!
- 这个SQl 怎么写
- 去除重复值问题
- SSIS的转换组件问题
- 求SQL语句(在线等待)
- 如何限制查询的记录为从第A条开始的共B条,我用limit A,B 但是sqlserver和oracle好象都不支持limit
- Attempt to ininiate a new SQL SErver operation with results pending是什么意思?
- 什么时候该用存储过程?邹老大能给我发一些资料么
- 谁能帮我写个存储过程?
select top 20 [id] from yourtable where [id] in(select top 60 [id] from yourtable order by [id] ASC)
ORDER BY [ID] DESC
pbsql(风云)兄的方法试过,还是错误数据
select top 20 * from (select top 60 * from table order by time asc) b
order by time desc
jackxing(Jack) 兄,我是要按时间排序。而且是先排序再获得结果。根本的需求就是根据时间排序获取分页显示记录
应该是没有问题的,楼主把有问题的数据帖出来给大家测试一下.
declare @t table(a int primary key,b int)
insert @t select 1,9
union all select 2,8
union all select 3,7
union all select 4,6
union all select 5,5
union all select 6,4
union all select 7,3
union all select 8,2
union all select 9,1--查询1
select top 2 * from @t
where a not in(select top 2 a from @t order by b desc)/*--结果a b
----------- -----------
3 7
4 6(所影响的行数为 2 行)
--*/
--查询2
select top 2 * from @t
where a not in(select top 2 a from @t order by b desc)
order by b /*--结果a b
----------- -----------
9 1
8 2(所影响的行数为 2 行)
--*/
b=8,9两条记录后的结果中,取前两条,就是取b=7,6两条在查询2中,得到的结果是排除了
b=8,9两条记录后的结果中,先按b从小大大排序,再取前两条,就是b=1,2的两条这显然是与要求不符合的,要求是先取数,再排序,而处理则变成了先排序,再取数
结果当然不对
select top 20 id from table where id not in(select top 40 id from table order by time desc)
)a order by time