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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:58:54+00:00 2026-06-01T11:58:54+00:00

I have a question about my mysql query. I want to count the number

  • 0

I have a question about my mysql query.
I want to count the number of records per day.
That works, but I also want to see the dates on which the count is 0.
The dates where the total is 0 is not in the resultset.
How do I do that?
This is my current query:

SELECT COUNT(id) AS total_per_day, 
DATE_FORMAT(reg_date, "%Y-%m-%d") as my_date 
FROM my_table GROUP BY my_date

Thanks in advance for your replies.

  • 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-01T11:58:56+00:00Added an answer on June 1, 2026 at 11:58 am

    Try this query –

    -- Create this temp. table firstly!
    -- CREATE TABLE days(d int);
    -- INSERT INTO days(d) VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9);
    
    SELECT t.day, COUNT(mt.id) total_per_day FROM (
      SELECT
        min_date + INTERVAL t1.d + t2.d * 10 DAY day,
        min_date,
        max_date
      FROM days t1, days t2,
        (SELECT MIN(DATE(reg_date)) min_date, MAX(DATE(reg_date)) max_date FROM my_table) t3
      HAVING day BETWEEN min_date AND max_date) t
      LEFT JOIN my_table mt
        ON t.day = DATE(mt.reg_date)
    GROUP BY t.day
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about converting charset from inside mysql query. I have a
I have this urgent question about date in php. I want to query the
I have a question about how GC works in Java. Consider the following code:
Question is similar to this one How to write a MySQL query that returns
I have a simple question about MySQL and PHP here. Let's say I have
I have a question about relational databases. I know that when using this I
I have a bit of an upsert type of question... but, I want to
I asked a question about creating temporary/ virtual ids for query results, mysql &
I use the cakePHP framework I have a question about how models handle MySQL
I have question about parsing in Html helper : I have sth like: @foreach

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.