At the moment I have 2 different mysql queries:
Query 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
Query 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
Now the difference between these is in query 1 I’m counting the number of accepted griefs per month and in query 2 I’m counting the number of records submitted per month – counting different columns
What I want to do it either a) get this into a single query or b) be able to merge the results into 1 table.
I want the output to be as follow:
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
Is this possible, or am I barking up the wrong tree entirely?
Thanks!
You can do this in one query:
EDIT: This is a bit unorthodox, but it would (most likely) give you what you’re after: