1,617
社区成员
发帖
与我相关
我的任务
分享
17:00:38 scott@TUNGKONG> with tab as
17:00:44 2 (
17:00:44 3 select '客户1' cust,'产品1' product,'2009-01-11' cDate,32 num,64000 Money from dual
17:00:44 4 union all
17:00:44 5 select '客户2' cust,'产品2','2009-02-11',32,64000 from dual
17:00:44 6 union all
17:00:44 7 select '客户3' cust,'产品3','2009-03-11',32,64000 from dual
17:00:44 8 union all
17:00:44 9 select '客户4' cust,'产品4','2009-04-11',32,64000 from dual
17:00:44 10 union all
17:00:44 11 select '客户5' cust,'产品5','2009-05-11',32,64000 from dual
17:00:44 12 )
17:00:44 13 select cust,product,decode(substr(cDate,6,2),'01',num,0) "1月",decode(substr(cDate,6,2),'02',num,0) "2月",
17:00:44 14 decode(substr(cDate,6,2),'03',num,0) "3月",decode(substr(cDate,6,2),'04',num,0) "4月",decode(substr(cDate,6,2),'05',num,0) "5月"
17:00:44 15 from tab;
CUST PRODU 1月 2月 3月 4月 5月
----- ----- ---------- ---------- ---------- ---------- ----------
客户1 产品1 32 0 0 0 0
客户2 产品2 0 32 0 0 0
客户3 产品3 0 0 32 0 0
客户4 产品4 0 0 0 32 0
客户5 产品5 0 0 0 0 32
已用时间: 00: 00: 00.03
with tab as
(
select '客户1' cust,'产品1' product,'2009-01-11' cDate,32 num,64000 Money from dual
union all
select '客户2' cust,'产品2','2009-02-11',32,64000 from dual
union all
select '客户3' cust,'产品3','2009-03-11',32,64000 from dual
union all
select '客户4' cust,'产品4','2009-04-11',32,64000 from dual
union all
select '客户5' cust,'产品5','2009-05-11',32,64000 from dual
)
select cust,product,decode(substr(cDate,6,2),'01',num,0) "1月",decode(substr(cDate,6,2),'02',num,0) "2月",
decode(substr(cDate,6,2),'03',num,0) "3月",decode(substr(cDate,6,2),'04',num,0) "4月",decode(substr(cDate,6,2),'05',num,0) "5月"
from tab;