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
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
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
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表
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
或: 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
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
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 )
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
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
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
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
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
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
(
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
)