See the following SQL:
SELECT M.username, count(*) as Total, date(status_date) as Date FROM com_result
LEFT JOIN members as M on M.member_id = com_result.member_id
GROUP BY date(status_date), com_result.member_id Order By status_date DESC
This will show total numbers of records base on DATE and member_id
Example Result:
+----------+-------+------------+
| username | Total | DATE |
+----------+-------+------------+
| bx7 | 3 | 2012-09-10 |
| bx2 | 25 | 2012-09-04 |
| bx2 | 401 | 2012-09-03 |
| bx1 | 703 | 2012-09-02 |
| bx4 | 1075 | 2012-09-02 |
+----------+-------+------------+
It work well, now I want to merge/union to another same and its same table structure. Second SQL:
SELECT M.username, count(*) as Total, date(status_date) as Date FROM com_result_b
LEFT JOIN members as M on M.member_id = com_result_b.member_id
GROUP BY date(status_date), com_result_b.member_id Order By status_date DESC
Assume the result from com_result would be:
| bx2 | 25 | 2012-09-04 |
And the result from com_result_b would be:
| bx2 | 50 | 2012-09-04 |
So when it merged/union – I want the result be like:
| bx2 | 75 | 2012-09-04 |
As you can see the value of Total increased from same Date from two tables. How can that be done?
With a SUM