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 8945655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:17:55+00:00 2026-06-15T12:17:55+00:00

SQL Question: I have this query: SELECT MONTHNAME(date) AS month, Year(getdate()) AS Year, COUNT(*)

  • 0

SQL Question:

I have this query:

SELECT MONTHNAME(date) AS month, Year(getdate()) AS Year, COUNT(*) AS monthly_sales_count
FROM orders
WHERE status = 0
AND YEAR(date) = 2012
GROUP BY month;

Which gives me results for 2012 per month.

How can I add the results for 2011 in one set of data, so i would get something like this:

Month       Year       Monthly_sales_count
december    2012        6576
november    2012        8788
october     2012        7676
september   2012          56
august      2012         345
july        2012        3356
june        2012        6563
may         2012        3245 
april       2012       25234
march       2012         234
february    2012         454
january     2012       24352
december    2011        6576
november    2011        8788
october     2011        7676
september   2011        1313
august      2011        1343
july        2011        2243
june        2011         656
may         2011        3234
april       2011      435345
march       2011       34345
february    2011        2134
january     2011        3412
  • 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-15T12:17:57+00:00Added an answer on June 15, 2026 at 12:17 pm
    SELECT MONTHNAME(date) AS month, Year(date) AS Year, COUNT(*) AS monthly_sales_count
    FROM orders
    WHERE status = 0
    AND YEAR(date) IN (2011, 2012)
    GROUP BY month, year
    ORDER BY year, month;
    

    Though I’d look to make the WHERE clause sargable (make use of index)

    SELECT MONTHNAME(date) AS month, Year(date) AS Year, COUNT(*) AS monthly_sales_count
    FROM orders
    WHERE status = 0
        AND date >= '20110101' AND date < '20130101'
    GROUP BY month, year;
    

    NOTE:
    You were doing YEAR(GETDATE()), whereas I’ve assumed you actually want to do YEAR(date) – if what you had was deliberate, then will need more info on exact requirements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query below: SELECT q.QuestionId,GROUP_CONCAT(DISTINCT Answer SEPARATOR '') AS Answer FROM Question
SQL query question I have a query like select proposal_id, service_id,account_type from table1 The
I have a small sql question for you. I have two queries: SELECT tbl_CostPrevisions.Month,
I have this 3 sql questions: $producent = mysql_fetch_array(mysql_query( SELECT FieldValue FROM `xy8vx_rsform_submission_values` WHERE
Suppose I have this query SELECT * FROM ( SELECT * FROM table_a WHERE
I have below SQL query: SELECT * FROM ( SELECT S.aCol, S.bCol, S.cCol, ROW_NUMBER()
Imagine I have the following SQL query: SELECT id,name FROM user WHERE id IN
I have this question in which I have a SQL Server Compact Edition database
In Microsoft SQL Server: I have seen this question several times, but can't see
I have a question on Date difference in (My)Sql with c#. In my database,

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.