sqlserver2000 top语句怎么添加排序序号

西门呀在吹雪 2012-05-17 10:30:53
sqlserver2000 top语句怎么添加排序序号 我想取前十条 同时按照降序排列并加上序号
...全文
194 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
人生无悔 2012-05-17
  • 打赏
  • 举报
回复

select top 10 id=identity(int,1,1),yourcolums into #t from yourtable
select id as 排序序号,yourcolumns from #t order by id desc
drop table #t
百年树人 2012-05-17
  • 打赏
  • 举报
回复
select *,
序号=(select count(1) from (select top 10 * from tb order by id) b where b.id>=a.id)
from
(select top 10 * from tb order by id) a
order by 序号

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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