MSSQL PIVOT 实现行列转置
create table #temp
(
ProdStep varchar(40),
ModuleStatus varchar(40),
Cnt int
);
insert into #temp values('DA','CannotMeet',4);
insert into #temp values('DA','Meet',1);
insert into #temp values('WB','CannotMeet',38);
select * from #temp;
select ProdStep, isnull(CannotMeet,0) as CannotMeet,ISNULL(Meet,0) as Meet
from
#temp
pivot
(
sum(Cnt)
for ModuleStatus in
(CannotMeet,Meet)
)
as pvt