日期:2014-05-16  浏览次数:20738 次

oracle decode
create table sale(
month char(6)    ,     
sell number(10,2) 
);
insert into sale values(200001,1000);
insert into sale values(200002,1100);
insert into sale values(200003,1200);
insert into sale values(200004,1300);
insert into sale values(200005,1400);
insert into sale values(200007,1600);
insert into sale values(200101,1100);
insert into sale values(200202,1200);
insert into sale values(200301,1300);
/*  想要转化为以下结构的数据:
  year   char(4)      --年份
  month1  number(10,2)   --1月销售金额
  month2  number(10,2)   --2月销售金额
  month3  number(10,2)   --3月销售金额
*/
create or replace view 
v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12)
  as
  select
  substrb(month,1,4),
  sum(decode(substrb(month,5,2),'01',sell,0)),
  sum(decode(substrb(month,5,2),'02',sell,0)),
  sum(decode(substrb(month,5,2),'03',sell,0)),
  sum(decode(substrb(month,5,2),'04',sell,0))
from sale ;
请问大神们这样写为什么总是报错。
请大神帮我改正一下
------解决方案--------------------
有 sum 函数,应该有 group by   substrb(month,1,4),