select 
( select monthtotal from monthtotal where [month]= month(getdate()) ) 
-
( select monthtotal from monthtotal where [month]=(case when month(getdate())=1 then 12 else month(getdate())-1 end) ) 
as diffrence

解决方案 »

  1.   


    select monthtotal-(select monthtotal from monthtotal where month(yearmonth)=month('某年某月')-1) from monthtotal where month(yearmonth)=month('某年某月')
      

  2.   


    create table ss
    (
    date1 datetime primary key,
    num int)insert into ss 
    select '2007-1-1',100
    union 
    select '2007-2-1',120
    union 
    select '2007-3-1',150
    union 
    select '2007-4-1',190
    union 
    select '2007-5-1',220
    ==============================
    select date1, num-(select num from ss where (datepart(month,A.date1)- datepart(month,date1)=1) and 
    datepart(year,date1)=datepart(year,A.date1) ) from ss A
    ========================================
    2007-01-01 00:00:00.000 NULL
    2007-02-01 00:00:00.000 20
    2007-03-01 00:00:00.000 30
    2007-04-01 00:00:00.000 40
    2007-05-01 00:00:00.000 30