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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:28:23+00:00 2026-06-01T18:28:23+00:00

In sql I want to show statistics data, so I’d like to show sums

  • 0

In sql I want to show statistics data, so I’d like to show sums from all weekdays, by showing 0 for the weekday that doesn’t exist. Same goes with month, hours, years….

The problem is that there is no table to join to to get the missing days.
Is there a clean method to do this?

Thank you

Edit :
The DB and data is irrelevent but I’m using Oracle DB and Mysql, simply put if i want to do

SELECT SUM(SALES) FROM SALES_TABLE WHERE SALES_DATE BETWEEN DATE1 AND DATE2 GROUP BY WEEKDAY

how to change this to get 0 for example on sundays, and not get SATURDAY :4, MONDAY:4

  • 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-01T18:28:25+00:00Added an answer on June 1, 2026 at 6:28 pm

    You could create a table with day names in it, and then do a left join on that table.

    It’d help to have a look at the table structure you have, but if I was going to do it, I’d do something like the following:

    create table stats (dayname varchar(3), "value" int);
    create table daynames (dayname varchar(3));
    insert into stats values ('Sun', 5), ('Mon', 4), ('Wed', 13), ('Sun', 3), ('Tue', 5), ('Sat', 5), ('Mon', 32);
    insert into daynames values ('Sun'),('Mon'),('Tue'),('Wed'),('Thu'),('Fri'),('Sat');
    
    select daynames.dayname, sum("value") from daynames left outer join stats on stats.dayname=daynames.dayname group by daynames.dayname;
    
    | dayname | sum |
    |---------+-----|
    | Fri     |     |
    | Mon     | 36  |
    | Sat     | 5   |
    | Sun     | 8   |
    | Thu     |     |
    | Tue     | 5   |
    | Wed     | 13  |
    

    You’ll have nulls for the sums on dates that aren’t represented in your data, but you can convert them to zeros, depending on your database server.

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

Sidebar

Related Questions

I want to write an SQL statement like below: select * from tbl where
I am using SQL Server 2000. My table show data like when I issue
Hello i want to show data from table where i have to show only
First of all I want to show how I made this in SQL: Both
In SQL Server, I want to show all items for a particular day. What
let say I want to show only 100 result from a sql query string
I want to show data from the last month (not form months past though),
I want to use a query like: sql(select name where id > 10 and
I want to write an SQL query using the LIKE keyword. It should search
This is probably easy, but eludes me. SQL server2005 I want to show top

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.