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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -