22,209
社区成员
发帖
与我相关
我的任务
分享
select
编号,名称,
sum(case when 经费分类='分类1' then 支出金额 else 0 end) 分类1,
sum(case when 经费分类='分类2' then 支出金额 else 0 end) 分类2
from
tb
group by
编号,名称
select 编号,名称,sum(case when 经费分类='分类1' then 支出金额 else 0 end) 分类1,
sum(case when 经费分类='分类2' then 支出金额 else 0 end) 分类2
from tb
group by 编号,名称
select * from tb
pivot(
max(支出金额) for 经费分类 in ([分类1],[分类2])
) as p
select a.编号,a.名称,a.支出金额 as 分类1,b.支出金额 as 分类2
from ta a , ta b
where a.编号=b.编号
and a.名称=b.名称
and a.经费分类='分类1'
and b.经费分类='分类2'
select a.编号,a.名称,a.支出金额 as 分类1,b.支出金额 as 分类2
from ta a inner join ta b on a.编号=b.编号 and a.名称=b.名称 and a.经费分类='分类1' and b.经费分类='分类2'