I am on SQL Server 2012 and have a table that looks similar to below:
Amount Itype hPlant PostDate
22.45 2 dplf 01/01/2016
45.55 2 dplf 01/01/2016
965.32 4 dplf 02/01/2016
14.25 3 dplf 01/01/2016
72.36 3 esch 01/01/2016
114147.77 2 dplf 01/01/2016
9641.25 4 dplf 01/01/2016
300.00 2 dplf 02/01/2016
I need to select the sum of amount with an ityp=2 and date=01/01/2016 and the sum of amount with itype=3 and date=01/01/2016 and plant=dplf plus some other data from various other tables.
How do I select the sums on 2 different criteria from one table. I have something similar to this:
,convert(varchar,tr.date,1)+' ' +'TB Upload' Reference
from trans tr
inner join plant p on p.hmy=tr.hplant
inner join trans tr2 on tr2.hplant=tr.hplant
where tr.date='01/01/2016' and tr.itype=2
and tr2.itype=3 and tr2.date='01/01/2016'
group by tr.date,p.scode
my results are not the same as if I ran them individually. Please help!