mysql - select from two tables and group by a common column date in both tables -
guys looked solution not problem grateful if have 3 tables term1
,term2
,term3
have identical columns adm
,date
, amountneeded
,amountpaid
, date format yyyy-mm-dd
need retrieve total amountpaid
3 tables , group
year
the result should be
year total 2012 323000 2013 423000
try this
select tyear,sum(total) ( select datepart(yyyy,date) tyear ,sum(amountpaid) total term1 group datepart(yyyy,date) union select datepart(yyyy,date) tyear ,sum(amountpaid) total term2 group datepart(yyyy,date) union select datepart(yyyy,date) tyear ,sum(amountpaid) total term1 group datepart(yyyy,date) )a group tyear
Comments
Post a Comment