请参阅以下 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
DATE
这将显示基于和的记录总数member_id
示例结果:
+----------+-------+------------+
| 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 |
+----------+-------+------------+
它工作得很好,现在我想合并/联合到另一个相同且相同的表结构。 第二条 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
假设结果com_result
是:
| bx2 | 25 | 2012-09-04 |
结果com_result_b
是:
| bx2 | 50 | 2012-09-04 |
所以当它合并/联合时 - 我希望结果如下:
| bx2 | 75 | 2012-09-04 |
如您所见,Total
从两个表中的同一日期增加的值。怎么可能呢?