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

  • Home
  • SEARCH
  • 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 6180355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:49:50+00:00 2026-05-24T00:49:50+00:00

I am trying to retrieve results from this query, but it is not fetching

  • 0

I am trying to retrieve results from this query, but it is not fetching any record:

SELECT DATE_FORMAT(BILLDATE,'%M-%Y'), SUM(GROSSAMOUNT), SUM(NETAMOUNT)
FROM BILLDETAILS
WHERE DATE_FORMAT(BILLDATE,'%M-%Y') BETWEEN 'May-2011' AND 'Jul-2011'
GROUP BY MONTH(BILLDATE), YEAR(BILLDATE)
ORDER BY YEAR(BILLDATE) DESC, MONTH(BILLDATE);

I also want to display SUM(GrossAmount) and Sum(NetAmount) as, for example, 1,10,20,356

  • 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-05-24T00:49:50+00:00Added an answer on May 24, 2026 at 12:49 am

    Your query is doing a string comparison, not a date comparison. Try something like this instead:

    SELECT DATE_FORMAT(BILLDATE,'%M-%Y'), SUM(GROSSAMOUNT), SUM(NETAMOUNT)
    FROM BILLDETAILS
    WHERE BILLDATE BETWEEN '2011-05-01' AND '2011-07-01'
    GROUP BY MONTH(BILLDATE), YEAR(BILLDATE)
    ORDER BY YEAR(BILLDATE) DESC, MONTH(BILLDATE);
    

    There are a variety of ways to specify the dates in the WHERE clause. Have a look at the Date and Time Functions reference for alterntives. Example:

    ...
    WHERE BILLDATE BETWEEN '2011-05-01' AND '2011-05-01' + INTERVAL 2 MONTH
    ...
    

    You may find the STR_TO_DATE function useful for converting strings to dates:

    SELECT STR_TO_DATE('May-2011', '%M-%Y');
    +----------------------------------+
    | STR_TO_DATE('May-2011', '%M-%Y') |
    +----------------------------------+
    | 2011-05-00                       |
    +----------------------------------+
    

    So your WHERE clause could be:

    WHERE BILLDATE BETWEEN STR_TO_DATE('May-2011', '%M-%Y')
                       AND STR_TO_DATE('Jul-2011', '%M-%Y')
    

    To format the value, use the FORMAT() function:

    SELECT FORMAT('11020356', 0);
    +-----------------------+
    | FORMAT('11020356', 0) |
    +-----------------------+
    | 11,020,356            |
    +-----------------------+
    

    …although formatting is usually best left to the application. If you format it in MySQL, processing it in the application might become a bit tricky.

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

Sidebar

Related Questions

Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm stuck on a MDX query, I'm trying to retrieve the following results: [Time].[2009]
I am trying to retrieve results from a DB in a resultset. However i
I am trying to use a dynamic linq query to retrieve an IEnumerable<T> from
i am trying to select information from my mysql database with this statement after
I'm trying to create a efficient query which will retrieve 'projects' from a database
I'm trying to retrieve images from wikimedia using the existing api, but there seems
I'm trying to retrieve data from a JSON object that looks like this: stdClass
I'm trying to use e4x to retrieve xml from the result event thrown when
I'm trying to retrieve a file from a server using SFTP (as opposed to

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.