最近做一份统计报表,有日期(date),总金额(money), 现要统计每个月份金额对比上个月的增长率,头痛的事,

解决方案 »

  1.   

    为一视图,就两个字段(date,money)
      

  2.   

    创建一个视图:
    Create View YourView As Select AddMonths( YourMonth, -1 ), YourValue From YourTable;
    然后是用下面的语句:
    Select A.Month, A.Value, B.Value, ( B.Value / A.Value - 1 )
         From YourTable A, YourView B
         Where A.Month = B.Month;以上语句在Oracle上测试成功!!!
      

  3.   

    declear @month int
      set @month=1while (@month=13) do begin
     if @month=1 do begin
      select (select sum(money) 
              from [view]
              where month([data])=@month) / (select sum(money)
                                             from [view]
                                             where month([data])=12)
     end
     else begin
         select (select sum(money) 
              from [view]
              where month([data])=@month) / (select sum(money)
                                             from [view]
                                             where month([data])=@month-1)
     end
    end
      

  4.   

    在编一个统计当月的视图不久搞定了???Create View MonthSum As Select Month, Sum( Value ) From YourTable
           Group By Month;