我有一张桌子收入
+------------+--------+--------+
| Date | Amount | Status |
+------------+--------+--------+
| 2012-01-03 | 200 | 4 |
| 2012-02-12 | 300 | 4 |
| 2012-07-07 | 200 | 4 |
| 2012-08-15 | 300 | 4 |
| 2012-08-17 | 250 | 4 |
| 2012-09-17 | 250 | 3 |
+------------+--------+--------+
和其他一个结果
+------------+--------+
| Date | Amount |
+------------+--------+
| 2012-03-22 | 50 |
| 2012-07-02 | 50 |
| 2012-08-19 | 100 |
| 2012-08-22 | 70 |
+------------+--------+
当我加入这两个表(第一个只有状态为 4 的表)时,我需要得到这个结果:
+------+-----------+--------+---------+--------+
| Year | Month | Income | Outcome | Profit |
+------+-----------+--------+---------+--------+
| 2012 | January | 200 | 0 | 200 |
| 2012 | February | 300 | 0 | 300 |
| 2012 | March | 0 | 50 | -50 |
| 2012 | April | 0 | 0 | 0 |
| 2012 | Jun | 0 | 0 | 0 |
| 2012 | July | 200 | 50 | 150 |
| 2012 | August | 550 | 170 | 380 |
| 2012 | September | 0 | 0 | 0 |
| 2012 | October | 0 | 0 | 0 |
| 2012 | November | 0 | 0 | 0 |
| 2012 | December | 0 | 0 | 0 |
+------+-----------+--------+---------+--------+
如何进行查询以获得这样的结果?
非常感谢,