27,579
社区成员
发帖
与我相关
我的任务
分享
declare @tt table(name varchar(20),c int,type varchar(20))
insert into @tt
select '王',20,'水' union all
select '王',30,'电' union all
select '王',23,'电' union all
select '张',24,'水' union all
select '张',20,'电'
select name,min(case when type='水' then c else 0 end) as 水,
min(case when type='电' then c else 0 end) as 电,sum(case when type='水' or type='电' then c else 0 end) as 合计
from @tt
group by name