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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:34:52+00:00 2026-06-17T22:34:52+00:00

I am trying to get the date and SUM(total) for last 7 days. I

  • 0

I am trying to get the date and SUM(total) for last 7 days. I am trying this code and getting date NULL and daily_sale 0.00

SELECT
  date,
  IFNULL( SUM( total ), 0 ) AS daily_sale
FROM sales
WHERE date BETWEEN NOW()
    AND DATE_SUB(NOW(), INTERVAL 7 DAY)

I am note sure how to get the date and daily total sale. I want get results as

date       daily_sale    
2013-01-29 500.00
2013-01-28 500.00
2013-01-27 500.00
2013-01-26 500.00
...
2013-01-23 500.00
  • 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-17T22:34:54+00:00Added an answer on June 17, 2026 at 10:34 pm

    You can try with interval - 7 day:

    SELECT  date, SUM(Coalese(total,0)) AS daily_sale
    FROM yourtable
    WHERE date BETWEEN NOW()  AND DATE_ADD(NOW(), INTERVAL -7 DAY)
    

    Not sure why between didn’t work, check this out:

    SQLFIDDLE DEMO

    select dates, sum(coalesce(daily_sale,0)) as total
    from sales
    where dates <= NOW()
    and dates >= Date_add(Now(),interval - 7 day)
    group by dates
    ;
    
    |                          DATES | TOTAL |
    ------------------------------------------
    | January, 23 2013 00:00:00+0000 |   500 |
    | January, 24 2013 00:00:00+0000 |   500 |
    | January, 27 2013 00:00:00+0000 |  1500 |
    | January, 28 2013 00:00:00+0000 |  1000 |
    | January, 29 2013 00:00:00+0000 |   500 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the following error when trying to get the sum in this Linq
i am trying to get date from my implementation of jquery date picker, add
I am trying to get date from Jquery ui date-picker by dropping some events
i'm trying to get date from UIDatePicker (MM-dd format) and to check if its
I am trying to get a date object from a string from an input.
I'm trying to get the exact time and date when users select a button,
I have written a query : SELECT YEAR(Date),SUM(replace(price, ',', '')) FROM example GROUP BY
I have a query as follows. select strftime('%Y-%m',A.traDate) as Month,sum(A.TraAmt) as Total,C.GroupType from TransactionTbl
New to PDO ... i am trying to get sum but getting error here
Hello every One i am trying to get Ist date of All months in

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.