目前我有2个不同的mysql查询:
查询 1
SELECT monthname( calendar.datefield ) AS date,
year(calendar.datefield) as year, calendar.datefield, COUNT(all_griefs_tbl.actioned_status ) AS total_griefs,
all_griefs_tbl.actioned_status, all_griefs_tbl.game
FROM all_griefs_tbl
RIGHT JOIN calendar
ON ( DATE(all_griefs_tbl.actioned_date ) = calendar.datefield )
AND all_griefs_tbl.actioned_status = 'accepted'
WHERE calendar.datefield
BETWEEN DATE_ADD(CURDATE(), INTERVAL -12 MONTH) AND CURDATE()
GROUP BY year( calendar.datefield ) DESC , month( calendar.datefield ) DESC
查询 2
SELECT monthname( calendar.datefield ) AS date,
year(calendar.datefield ) AS year, calendar.datefield,
COUNT(all_griefs_tbl.actioned_status ) AS total_submitted,
all_griefs_tbl.actioned_status, all_griefs_tbl.game
FROM all_griefs_tbl
RIGHT JOIN calendar
ON ( DATE( all_griefs_tbl.date ) = calendar.datefield )
WHERE calendar.datefield BETWEEN DATE_ADD( CURDATE( ) , INTERVAL -12 MONTH ) AND CURDATE( )
GROUP BY year( calendar.datefield ) DESC , month( calendar.datefield ) DESC
现在这些之间的区别在于查询 1 我正在计算每月接受的悲伤的数量,而在查询 2 中我正在计算每月提交的记录数 - 计算不同的列
我想做的是a)将其放入单个查询中或b)能够将结果合并到1个表中。
我希望输出如下:
Month Year Total Griefs Total Submitted
------------ ------------ ------------ ------------
April 2012 14 2
March 2012 0 8
February 2012 0 6
January 2012 0 13
December 2011 0 7
November 2011 0 10
October 2011 0 0
September 2011 0 0
August 2011 0 6
July 2011 0 3
June 2011 0 2
May 2011 0 0
April 2011 0 0
这是可能的,还是我完全找错了树?
谢谢!