首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

查询除第一条纪录外的前四条纪录。解决思路

2012-05-14 
查询除第一条纪录外的前四条纪录。查询除第一条纪录外的前四条纪录:select Top 4 * from news where id not

查询除第一条纪录外的前四条纪录。
查询除第一条纪录外的前四条纪录:
select Top 4 * from news where id not in(select top 1 * from news order by id desc) order by id desc


我这样写好像不对。没有输出数据!请问应该怎么写?

[解决办法]
如果是SQL2005数据库可以这么写 select top 4 * from (select row_number() over(order by id desc ) as rowid,* from [table]) as t where rowid between 2 and 4

还有一种就是先读出前五条数据 然后忽略第一条:
do while not rs.eof
a =a+1
if a>1 then
.....
end if
rs.movenext
loop
a = 0

热点排行