Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:12:06+00:00 2026-06-02T09:12:06+00:00

At the moment I have 2 different mysql queries: Query 1 SELECT monthname( calendar.datefield

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:12:07+00:00Added an answer on June 2, 2026 at 9:12 am

    You can do this in one query:

    SELECT 
        monthname( calendar.datefield ) AS date,
        year(calendar.datefield) as year, 
        calendar.datefield,
        SUM(IF(all_griefs_tbl.actioned_status = 'accepted', 1, 0)) AS total_griefs,
        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.actioned_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
    

    EDIT: This is a bit unorthodox, but it would (most likely) give you what you’re after:

    SELECT
        month(date_add(curdate(), interval seq.mm months)),
        year(date_add(curdate(), interval seq.mm months)),
        (SELECT count(1)
           FROM all_griefs_tbl
          WHERE actioned_status = 'accepted'
            AND month(action_date) = month(date_add(curdate(), interval seq.mm months))
            AND year(action_date) = year(date_add(curdate(), interval seq.mm months))) as total_griefs
        (SELECT count(1)
           FROM all_griefs_tbl
            AND month(date) = month(date_add(curdate(), interval seq.mm months))
            AND year(date) = year(date_add(curdate(), interval seq.mm months))) as submitted_griefs
    FROM
        (SELECT -12 as mm UNION SELECT -11  as mmUNION SELECT -10  as mmUNION SELECT -9  as mm
         UNION SELECT -8 as mm UNION SELECT -7  as mm UNION SELECT -6 as mm UNION SELECT -5 as mm
         UNION SELECT -4 as mm UNION SELECT -3 as mm UNION SELECT -2 as mm UNION SELECT -1 as mm) seq
    ORDER BY
        mm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying a few different approaches to Javascript inheritance at the moment. I have
I have reached an impasse with my knowledge regarding mysql joins, and the query
So at the moment I have a multidimensional array string[,] items = new string[100,
At the moment I have a slider and an small input text box which
At the moment I have a jQuery do a POST to a Controller which
At the moment I have a DocumentViewer in a WPF window that displays an
At the moment I have a combobox that is populated from the name fields
at the moment I have my jQuery plugin running it's logic in if statments.
At the moment I have two tables, products and options . Products contains id
At the moment I have the following code which works fine. label = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.