遗失的星空

导航

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

posted on 2015-04-30 09:44  遗失的星空  阅读(562)  评论(0编辑  收藏  举报