日期:2014-05-18  浏览次数:20490 次

SQL语句排序的记录顺序号?
请问怎样可以得到SQL语句查询时的记录编号:
例如:select   top   10   id,name   from   program   order   by   id
怎么可以可到第一条记录的编号是1,第二条的记录编号是2   ……   第十条的记录编号是10,先谢谢啦!

------解决方案--------------------
SELECT ROW_NUMBER() OVER(ORDER BY ID ) AS 'Row Number ',ID,NAME
FROM program
------解决方案--------------------
select top 10 BH=indentity(int,1),id,name into #t from program order by id
select * from #t
drop table #t

------解决方案--------------------
Sorry,更正下,indentity(int,1,1),上面的少了个 ",1 "
select top 10 BH=indentity(int,1,1),id,name into #t from program order by id
select * from #t
drop table #t
------解决方案--------------------
--如果 id 唯一

SELECT TOP 10
(SELECT COUNT(*)
FROM program
WHERE a.id > = id) AS 编号, id,name
FROM program as a
ORDER BY id


------解决方案--------------------
一楼的仁兄说的是2005的用法!2000没有!