查询除第一条纪录外的前四条纪录。

wqjywyg2009 2011-05-28 03:59:31
查询除第一条纪录外的前四条纪录:
select Top 4 * from news where id not in(select top 1 * from news order by id desc) order by id desc


我这样写好像不对。没有输出数据!请问应该怎么写?
...全文
70 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sweetbbs 2011-05-29
  • 打赏
  • 举报
回复
select top 4 * from
(select top 5 * from news order by id) t
order by id desc
lzp4881 2011-05-29
  • 打赏
  • 举报
回复
select Top 4 * from news where id not in(select top 1 id from news order by id asc) order by id asc
vstudiocn 2011-05-29
  • 打赏
  • 举报
回复
2楼正解
挨踢直男 2011-05-29
  • 打赏
  • 举报
回复
select Top 4 * from news where id not in(select top 1 id from news order by id desc) order by id desc
一aa一 2011-05-29
  • 打赏
  • 举报
回复
如果是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

28,404

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧