表 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  

解决方案 »

  1.   

    select id = identity(int,1,1) , (select distinct depot from a) into #A from a
      

  2.   

    select identity(int) id,depot,sum(favg) favg into #a from ta group by depot
    ?
      

  3.   

    select id = identity(int,1,1) , (select  depot from tablename group by depot ) into #tablenameB from tablename
      

  4.   

    create table a(fid int,depot varchar(20),favg numeric(20,6))
    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
      

  5.   

    insert into #A
    select  id = identity(int,1,1) , (select  depot from tablename group by depot )