I have two tables like below
tb1
Date Cr Dr
2018-04-29 100 50
2018-04-30 0 150
2018-05-01 250 100
2018-05-02 150 100
2018-06-10 300 250
2018-06-11 0 50
tb2
Date Cr
2018-05-01 350
2018-05-02 250
2018-06-10 300
2018-06-11 100
2018-06-15 200
2018-06-18 100
I need the following Result
Apr May Jun
Cr 100 1000 1000
Dr 200 200 300
Basically I have to add the respective Cr columns from both table and get the Dr from tb1 for the corresponding dates and create a monthly report.
I have tried
SELECT Date(tb1.Date) as sDate, SUM(tb1.Cr+tb2.Cr) sumcr, SUM(tb1.Dr) sumdr FROM tb1,tb1 WHERE Date(tb1.Date)=Date(tb2.Date) GROUP BY YEAR(sDate), MONTH(sDate) ORDER BY Date(sDate) ASC
I have tried LEFT and INNER JOINs too like below
SELECT *, SUM(tb1.Cr) as sumcr, SUM(tb1.Dr) as sumdr, SUM(tb2.Cr) as salecr Date(tb1.Date) as sDate FROM tb1 LEFT JOIN tb2 ON tb1.Date=tb2.Date GROUP BY MONTH(tb1.Date) ORDER BY MONTH(tb1.Date) ASC
All these give wrong results.
Where am I going wrong ?
Any help will be greatly appreeciated !