现有一个商品销售表sale,表结构为:
month char(6) --月份
sell number(10,2) --月销售金额
现有数据为:
200001 1000
200002 1100
200003 1200
想要转化为以下结构的数据:
month1 number(10,2) --1月销售金额
month2 number(10,2) --2月销售金额
month3 number(10,2) --3月销售金额
    
SQL语句为:
select
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)) 
from sale 
 
                    
                     
                    
                 
                    
                 
                
 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号