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

光关注股市了,很久没看SQL了,有个简单问题了,现在搞不了了...
如何给SQL查询的结果加上行号?查询出来100个,行号就显示1到100?
我直接用select   id=identity(1,1),col   from   table结果提示必须是SELECT     INTO   才能用IDENTITY.
还有什么办法,在查询里给结果集加上行号?

------解决方案--------------------
SQL2K通过临时表:

select id=identity(1,1),col into #temp from table
select * from #temp
------解决方案--------------------
如果有一列能区分大小,如id

SELECT * , xh=(SELECT COUNT(id) FROM tb WHERE id < a.id) + 1
FROM tb a
ORDER BY xh

如果没有任何一列能区分大小.

则使用
select id=identity(int,1,1) , * into temp from tb
select * from temp order by id