我有两张桌子:
表1
date | client | total
2015-01-01 | john | 85.00
2015-02-01 | alfred | 35.00
2015-03-01 | georgy | 125.00
表2
date | client | total
2015-01-01 | Wendy | 25.00
2015-02-01 | Monique | 19.00
2015-03-01 | Jack | 14.00
如果我想加入这些表格,我会这样做:
SELECT * FROM (SELECT date, client, total from table1
UNION ALL SELECT date, client, total from table2) a where date BETWEEN '2015-01-01' AND '2015-06-11';
我得到了这个:
date | client | total
2015-01-01 | john | 85.00
2015-01-01 | Wendy | 25.00
2015-02-01 | alfred | 35.00
2015-02-01 | Monique | 19.00
2015-03-01 | georgy | 125.00
2015-03-01 | Jack | 14.00
直到这里它很好但现在我想按年,月和总和值分组显示如下结果:
year | month | total
2015 | 01 | 110.00
2015 | 02 | 54.00
2015 | 03 | 139.00
如何修改我的查询?
我想要一些帮助。