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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:06:18+00:00 2026-05-23T22:06:18+00:00

I am trying to select the sum of an integer field for the past

  • 0

I am trying to select the sum of an integer field for the past 5 days, and I need to group it for each day.

I’m having a bit of issues figuring out the grouping. Here’s my sql query so far:

select 
    sum(`amount_sale`) as total 
from `sales` 
where the_date >= unix_timestamp((CURDATE() - INTERVAL 5 DAY))

that works fine for generating the sum for all 5 days together, but I need to break this down so that it shows the sum for each of the past 5 days i.e:

day 1 – $200

day 2- $500

day 3 – $20

etc.

  • 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-23T22:06:19+00:00Added an answer on May 23, 2026 at 10:06 pm
    SELECT  DATE(FROM_UNIXTIME(the_date)) AS dt, SUM(amount_sale) AS total
    FROM    sales
    WHERE   the_date >= UNIX_TIMESTAMP((CURDATE() - INTERVAL 5 DAY))
    GROUP BY
            dt
    

    To returns 0 for missing dates:

    SELECT  dt, COALESCE(SUM(amount_sale), 0) AS total
    FROM    (
            SELECT  CURDATE() - INTERVAL 1 DAY AS dt
            UNION ALL
            SELECT  CURDATE() - INTERVAL 2 DAY AS dt
            UNION ALL
            SELECT  CURDATE() - INTERVAL 3 DAY AS dt
            UNION ALL
            SELECT  CURDATE() - INTERVAL 4 DAY AS dt
            UNION ALL
            SELECT  CURDATE() - INTERVAL 5 DAY AS dt
            ) d
    LEFT JOIN
            sales
    ON      the_date >= UNIX_TIMESTAMP(dt)
            AND the_date < UNIX_TIMESTAMP(dt + INTERVAL 1 DAY)
    GROUP BY
            dt
    

    This is not a very elegant solution, however, MySQL lacks a way to generate recordsets from scratch.

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

Sidebar

Related Questions

I am trying to implement something like: Select thread from Thread where(Select Sum(thread.emails) from
I'm trying to select the order total sum ($) and invoice count over a
Trying to get a check sum of results of a SELECT statement, tried this
I'm trying to do a select SUM while doing other selects at the same.
I am trying to join 3 tables with the following sql statement Select Sum(OrderDetail_table.Price
I am trying a query like this in MYSQL select Sum(case when WindowsXP =
I was trying to do this: SELECT SUM(price) as total FROM ticketLine WHERE dateRegistered
I'm trying to select the SUM of a row where the ID matches a
Basically, I am trying the following: SELECT m.col1, SUM(SELECT col5 FROM table WHERE col2
I am trying to join a select disinct statement to a select sum statement.

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.