insert into a 
   select str,0,itype0count 
   union all
   select str,1,itype1count 
   union all
   select str,2,itype2count 

解决方案 »

  1.   

    insert into b(str, iType0Count) select str,Count from a where iType=0
    GO
    insert into b(str, iType1Count) select str,Count from a where iType=1 
    GO
    insert into b(str, iType2Count) select str,Count from a where iType=2
      

  2.   

    TRY:insert into b
       select distinct str ,
        (select Count from a where a.str=bb.str and a.itype=0),
        (select Count from a where a.str=bb.str and a.itype=1),
        (select Count from a where a.str=bb.str and a.itype=2)
    from a as bb
      

  3.   


    insert into b
    select str,sum(case iType when 0 then Count(int) else 0 end) as iType0Count,
    sum(case iType when 1 then Count(int) else 0 end ) as iType1Count,
    sum (case iType when 2 then Count(int) else 0 end ) as iType2Count
    from a
    group by str
      

  4.   

    insert b表 select str,case itype when 0 then count end,case itype when 1 then count end,case itype when 2 then count end from A表
      

  5.   

    insert into b 
    select str,sum(case itype when 0 then count else 0 end)a,
               sum(case itype when 1 then count else 0 end)b,
               sum(case itype when 2 then count else 0 end)c
    from A
      

  6.   

    或:
    insert b表 select str,sum(case itype when 0 then count else 0 end),sum(case itype when 1 then count else 0 end),sum(case itype when 2 then count else 0 end) from A表 group by str
      

  7.   

    insert into b 
    select str,sum(case itype when 0 then count else 0 end)a,
               sum(case itype when 1 then count else 0 end)b,
               sum(case itype when 2 then count else 0 end)c
    from A
    group by str
      

  8.   

    insert into b 
    (
    select str,sum(case itype when 0 then count else 0 end)a,
               sum(case itype when 1 then count else 0 end)b,
               sum(case itype when 2 then count else 0 end)c
    from A
    group by str
    )