Sunday, February 19, 2012

How to do comparison between current_year_amount vs previous_year_amount

Hi all,

I try to compare this year amount, A (i.e March 2003) with last year amount, B (i.e March 2002) to get a result, C. I need to calculate and store figure for each following month, then later compute variance from the C value i get.

May I know how to write SQL code that allow me to have both last year data n this year data in the furure? :eek: I only have current year figure now.

A thousand thanks!

SQL Junior,
Suh Fui ;)Here is a quick demo that you can apply to your issue.

select sum(case when convert(varchar(6),orderdate,112)='199607' then freight else 0 end) as 'Jul 96',
sum(case when convert(varchar(6),orderdate,112)='199707' then freight else 0 end) as 'Jul 97'
from northwind..orders

No comments:

Post a Comment