Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

sum by year

Below is a sample. I want it to return a sum of 2014 and a sum of 2013. I am not sure how to do it.

year 2014 = $110
year 2013 =$15
dif = $95


select

sum(case when year(DateShipped) = 2014 then (unit_dollar * QTYSHIPPED) else (unit_dollar * QTYSHIPPED)  end) as Incr2014

from table where year(qtyshipped) in ('2013', '2014')

Here is my sample data


id  Unit    qtyshipped  unit_dollar  DateShipped
1   watch    10         $100          2014-01-02 00:00:00.000
2   Pen      5          $10           2014-01-05 00:00:00.000
2   Notebook 3          $15           2013-01-05 00:00:00.000
etc
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBdotnet2005

ASKER

Thank you