select * from ( select top 2 from (select top 4 from t order by id) a order by id desc ) b order by id
先asc查出前4条,再desc查出2条
用游标 declare sy_cursor scroll cursor --创建游标,scroll选项允许使用每种游标移动选项,没指定则只能使用next for select name from [sy_table] open sy_cursor fetch absolute 3 from sy_cursor --从记录集第一条记录开始的数的第3条记录 close sy_cursor --使用完应该关闭游标 deallocate sy_cursor --删除游标
select top 2 from (select top 4 from t order by id) a order by id desc
) b
order by id
declare sy_cursor scroll cursor --创建游标,scroll选项允许使用每种游标移动选项,没指定则只能使用next
for
select name from [sy_table]
open sy_cursor
fetch absolute 3 from sy_cursor --从记录集第一条记录开始的数的第3条记录
close sy_cursor --使用完应该关闭游标
deallocate sy_cursor --删除游标