日期:2014-05-17 浏览次数:20964 次
--sql: with t as ( select 1 a,'01' b,'S' c, 4 d from dual union all select 1,'01','F', 8000 from dual union all select 1,'02','S', 211 from dual union all select 1,'02','F', 2 from dual union all select 1,'03','S', 22 from dual union all select 1,'03','F', 2 from dual union all select 1,'04','S', 85 from dual union all select 1,'05','F', 2 from dual union all select 1,'05','S', 15 from dual ) select a,b,'S' c,sum(case when c='S' then d else 0 end) S ,'F' d, sum(case when c='F' then d else 0 end) F from t group by a,b --result: 1 01 S 4 F 8000 1 02 S 211 F 2 1 03 S 22 F 2 1 04 S 85 F 0 1 05 S 15 F 2