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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:34:15+00:00 2026-06-15T01:34:15+00:00

I have a query like this: SELECT SUM(spend.price) AS total, WEEKDAY(spend.date) AS weekday FROM

  • 0

I have a query like this:

SELECT SUM(spend.price) AS total, WEEKDAY(spend.date) AS weekday
FROM spend
WHERE spend.date BETWEEN '2012-11-01' AND '2012-11-07'
GROUP BY WEEKDAY(spend.date) ;

Right now the query gives me only the days in which the user had some payments.

total weekday
60    2
10    3
3     5
3     6

But instead I want to give me 0 (zeros) for every day without payments.

total weekday
0     1
60    2
10    3
0     4
3     5
3     6
0     7

Table schema here.

  • 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-15T01:34:16+00:00Added an answer on June 15, 2026 at 1:34 am

    Here is the original syntax:

    SELECT SUM(spend.price) AS total, day AS weekday
    FROM (SELECT price, WEEKDAY(date) as day FROM spend WHERE date BETWEEN '2012-11-01' AND '2012-11-07'
    UNION ALL
    SELECT 0,0
    UNION ALL
    SELECT 0,1
    UNION ALL
    SELECT 0,2
    UNION ALL
    SELECT 0,3
    UNION ALL
    SELECT 0,4
    UNION ALL
    SELECT 0,5
    UNION ALL
    SELECT 0,6
    ) spend
    GROUP BY day ;
    

    And here is the shortened one:

    CREATE TEMPORARY TABLE tmp ( `price` int, `day` int );
    INSERT INTO tmp VALUES (0,0),(0,1),(0,2),(0,3),(0,4),(0,5),(0,6);
    SELECT SUM(spend.price) AS total, day AS weekday
    FROM (SELECT price, WEEKDAY(date) as day FROM spend WHERE date BETWEEN '2012-11-01' AND '2012-11-07'
    UNION ALL
    SELECT * FROM tmp
    ) spend
    GROUP BY day ;
    

    Here is a demonstration: http://sqlfiddle.com/#!2/8c323/3/0

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

Sidebar

Related Questions

I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a sql query that looks like this: SELECT SUM(A) AS expr1 FROM
I have query like this: SELECT *, SUM(ss.rank) as group_sum FROM Standard s, s.SubStandard
I have sql query like this: select a.x, a.y, sum(a.foo) as foo_sum from a
I have a Query Script like this: SELECT View1.OrderDate,View1.Email,SUM(View1.TotalPayments) FROM dbo.View1 WHERE (View1.OrderStatus =
I have a query like this SELECT tableA.field1, SUM(tableB.field4) AS the_sum FROM tableA LEFT
I have a query like this: SELECT t.type, SUM( t.external_account ) FROM u_contracts c,
I have a MySQL query like this: SELECT DAYNAME(CreatedAt) AS TheDay, SUM(Amount) AS TheSum
I have a query like this: select empno,name from emp where job = 'CLERK'
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales

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.