SQL 行列转换

 select r.id,remedycode as 编号,sum(case when item_id='51' then remedyfee else 0 end) as 布放光缆,
sum(case when item_id='206' then remedyfee else 0 end) as "顶管",
sum(case when item_id='33' then remedyfee else 0 end) as "更换井盖",
sum(case when item_id='34' then remedyfee else 0 end) as "更换井框",
sum(case when item_id='204' then remedyfee else 0 end) as "光缆割接(第一条光缆)",
sum(case when item_id='202' then remedyfee else 0 end) as "光缆接续(第一条光缆)",
sum(case when item_id='52' then remedyfee else 0 end) as "回收光缆",
sum(case when item_id='40' then remedyfee else 0 end) as "人(手)井升高(降底)",
sum(case when item_id='22' then remedyfee else 0 end) as "挖土(石方)"
from linepatrol_remedy r,linepatrol_remedy_bal_item bal
where r.id=bal.remedyid and r.contractorid='0000000001' and to_char(r.remedydate,'yyyy-mm')='2009-11'
group by remedycode,r.id

你可能感兴趣的:(sql)