日期:2014-05-17 浏览次数:20728 次
with a as(
select 1 编号,'A' 房间,20 数量,'张三' 负责 from dual
union all
select 2,'B',40,'李四' from dual
union all
select 3,'A',50,'王五' from dual
union all
select 4,'A',50,'赵六' from dual
union all
select 5,'C',70,'张三' from dual
)
select 负责,
sum(decode(房间, 'A', 数量, 0)) A,
sum(decode(房间, 'B', 数量, 0)) B,
sum(decode(房间, 'C', 数量, 0)) C
from a
group by 负责;
负责 A B C
---- ---------- ---------- ----------
王五 50 0 0
张三 20 0 70
李四 0 40 0
赵六 50 0 0