select
本月=sum(case when datediff(month,fdate,getdate())=0 then fAmount else 0 end),
本年=sum(case when datediff(year,fdate,getdate())=0 then fAmount else 0 end),
上年同期=sum(case when datediff(month,fdate,getdate())=1 then fAmount else 0 end)
from tblA
本月=sum(case when datediff(month,fdate,getdate())=0 then fAmount else 0 end),
本年=sum(case when datediff(year,fdate,getdate())=0 then fAmount else 0 end),
上年同期=sum(case when datediff(month,fdate,getdate())=1 then fAmount else 0 end)
from tblA
select 本月=(select sum(fAmount) from tblA where convert(char(7),fdate,120)='2004-11')
,本年=(select sum(fAmount) from tblA where year(fdate)=2004)
,上年同期=(select sum(fAmount) from tblA where convert(char(7),fdate,120)='2003-11')
select
本月=sum(case when datediff(month,fdate,getdate())=0 then fAmount else 0 end),
本年=sum(case when datediff(year,fdate,getdate())=0 then fAmount else 0 end),
上年同期=sum(case when datediff(month,fdate,getdate())=12 then fAmount else 0 end)
from tblA
declare @年月 char(7)
set @年月='2004-11'select 本月=(select sum(fAmount) from tblA where datediff(month,fdate,@年月+'-1')=0)
,本年=(select sum(fAmount) from tblA where datediff(year,fdate,@年月+'-1')=0)
,上年同期=(select sum(fAmount) from tblA where datediff(month,fdate,@年月+'-1')=12)
else 0
end ),
'本年'=sum(case when year(fdate)=year(getdate()) then fAmount
else 0
end ),
' 上年同期'=sum(case when year(fdate)=2003 and month(fdate)=11 then fAmount
else 0
end )
from tblA