sql在虚拟表中创建标识列

来源:百度知道 编辑:UC知道 时间:2024/05/28 15:13:15
在查询语句中我用了group by 所以表中的自增id没有用了,怎么给他加一个1,2,3..的列
我只希望用一句sql语句来处理.select identity(int,1,1) as id,name,xb into #temp from table这条语句中into是什么意思,我试了一下,不用into就会报错,能不能说的详细点,谢谢.

你先声明一个表,给这个表添加几列,包括一个标识列
例如:
declare @temp table
(
id int identity(1,1),
等等列
)
然后添加
insert @temp
select * from tablename

然后查询
select * from @temp

你创建临时表的时候可以制定的,给你写个例子吧:

select identity(int,1,1) as id,name,xb into #temp from table