表 a有字段
fid depot Favg
1 总仓库一 20
2 总仓库一 57.5
3 楼上仓库一 20.5
4 楼上仓库2 20
5 楼上仓库一 20.5
现在要建立临时表#A depot 字段是 表 a depot中不重复的id depot
自动加1 总仓库一
楼上仓库一
楼上仓库2
fid depot Favg
1 总仓库一 20
2 总仓库一 57.5
3 楼上仓库一 20.5
4 楼上仓库2 20
5 楼上仓库一 20.5
现在要建立临时表#A depot 字段是 表 a depot中不重复的id depot
自动加1 总仓库一
楼上仓库一
楼上仓库2
?
insert into a(fid,depot,favg)
select 1,'总仓库一',20
union all select 2,'总仓库一',57.5
union all select 3,'楼上仓库一',20.5
union all select 4,'楼上仓库2',20
union all select 5,'楼上仓库一',20.5select identity(int,1,1) as id,t.depot into #Adepot from (select distinct depot from a)tdrop table #Adepot
select id = identity(int,1,1) , (select depot from tablename group by depot )