现有两种方法解决,供参考:
1、SELECT IDENTITY(INT,1,1) AS 序号, avge FROM Table1
2、SELECT IDENTITY(INT,1,1) AS 序号, avge INTO #temp1 FROM Table1
SELECT * FROM #temp1
DROP TABLE #temp1
给查询出的SQL记录添加序号列,解决方法有以下两种
第一:
select ROW_NUMBER() OVER (ORDER BY a.字段 ASC) AS XUHAO,a.* from table a1
(table 为表名,字段为表a中的字段名)
第二:
select RANK() OVER (ORDER BY a.字段 ASC) AS XUHAO,a.* from table a1
(table 为表名,字段为表a中的字段名)
.使用临时表实现
SQL的IDENTITY函数可以提供自增的序号,但只能用在带有INTO table子句的SELECT语句中,所以如果可以使用临时表的情况下可以使用这种实现方法。
eg:
SELECT IDENTITY(INT,1,1) as seq,field1,field2,...,fieldn INTO tmpTableName FROM srcTableName;
SELECT * FROM tmpTableName;
DROP TABLE tmpTableName;
SELECT ROW_NUMBER() OVER (ORDER BY NEWID()) AS 序号,avge
select IDENTITY(int,1,1) as id,avge into #1 from xxx;
select * from #1;
加什么序号你给个例子啊
select identity(int,1,1) as 序号,avge from table