如何根据n行显示序列号作为第一列 [英] How to display serial number as first column based on the n number of rows

查看:80
本文介绍了如何根据n行显示序列号作为第一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何根据SQL查询中的n行显示序列号作为第一列...?

解决方案

< blockquote>在Microsoft MSDN上使用 ROW_NUMBER


如果你正在使用SQL Server 2005或更多使用此



  SELECT  ROW_NUMBER () OVER  ORDER   BY  ColumnName1) 作为 SrNo,ColumnName1,ColumnName2  FROM  TableName 


选择标识(int,1,1)为[Serial#],'Hello'AS [MyColumn] INTO #temp 


Hi,
How to display serial number as first column based on the n number of rows in SQL Query...?

解决方案

Use ROW_NUMBER on Microsoft MSDN


If you are using SQL Server 2005 or more than use this

SELECT ROW_NUMBER()  OVER (ORDER BY  ColumnName1) As SrNo, ColumnName1,  ColumnName2 FROM  TableName


SELECT identity(int,1,1) as [Serial#], 'Hello' AS [MyColumn] INTO #temp


这篇关于如何根据n行显示序列号作为第一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆