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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:33:41+00:00 2026-06-11T22:33:41+00:00

I am receiving a weird result in this MySQL query. I am attempting to

  • 0

I am receiving a weird result in this MySQL query.

I am attempting to return ‘orders’, grouped by month.

SELECT DATE_FORMAT(date_of_sale, '%b') AS date, SUM(quantity) AS items FROM order_elements JOIN orders ON order_elements.order_ref = orders.order_id WHERE cur_status = 1 AND quantity > 0 AND MONTH(date_of_sale) BETWEEN MONTH(CURDATE() - INTERVAL 8 MONTH) AND MONTH(NOW()) GROUP BY MONTH(date_of_sale) ORDER BY MONTH(date_of_sale) DESC

When I run the query to get orders between now and 8 months ago I get this result:

==================
| date   | items |
==================
| Sep    | 95    |
| Aug    | 110   |
| Jul    | 106   |
| Jun    | 110   |
| May    | 100   |
| Apr    | 130   |
| Mar    | 100   |
| Feb    | 94    |
| Jan    | 7     |
===================

January 30th is the EARLIEST AND FIRST date I have an order for. Ever other date_of_sale is later than Jan 30th.

When I run the same query but between now and 9 months ago, I get NO results.

I think it may have something to do with 9 months ago being equal to Dec and it falling onto a different year and causing some sort of issue, but I am not sure. Does anyone have any idea why searching back an extra month would return no results? Is it something to do with no data beyond Jan, or the Month being of a different year?

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-11T22:33:42+00:00Added an answer on June 11, 2026 at 10:33 pm

    When you query for this:

    BETWEEN MONTH(CURDATE() - INTERVAL 9 MONTH) AND MONTH(NOW())
    

    You are querying from month 12 – 9. Because 12 is greater than 9 there will be no results. But when you query for this:

    BETWEEN MONTH(CURDATE() - INTERVAL 8 MONTH) AND MONTH(NOW())
    

    You are querying from month 1 – 9.

    The solution is that you need to include the year in your query as well, and not just the number of the month.

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

Sidebar

Related Questions

I'm receiving this weird problem when updating the structure of my site. Site URL
I keep receiving this error... [2012-06-14 11:54:50,072: ERROR/MainProcess] Hard time limit (300s) exceeded for
I am receiving this Uncaught TypeError on a new website I am creating, but
I am receiving a parse error which is this: Parse error: syntax error, unexpected
Why am I receiving this Rake error: $ rake --version /Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not
I'm receiving an xml response and I now want to parse this. Currently what
This is a weird one, y'all. - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
I'm experiencing really weird behavior with the Socket.Connect method in C#. I am attempting
I'm creating a linked list data structure in C. However, I'm receiving some weird
I'm receiving data from an AJAX request, and it's really weird. I thought it

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.