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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:03:24+00:00 2026-06-04T02:03:24+00:00

I have SQL like this (where $ytoday is 5 days ago): $sql = ‘SELECT

  • 0

I have SQL like this (where $ytoday is 5 days ago):

$sql = 'SELECT Count(*), created_at FROM People WHERE created_at >= "'. $ytoday .'" AND GROUP BY DATE(created_at)';

I want this to return a value for every day, so it would return 5 results in this case (5 days ago until today).

But say Count(*) is 0 for yesterday, instead of returning a zero it doesn’t return any data at all for that date.

How can I change that SQLite query so it also returns data that has a count of 0?

  • 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-04T02:03:24+00:00Added an answer on June 4, 2026 at 2:03 am

    Without convoluted (in my opinion) queries, your output data-set won’t include dates that don’t exist in your input data-set. This means that you need a data-set with the 5 days to join on to.

    The simple version would be to create a table with the 5 dates, and join on that. I typically create and keep (effectively caching) a calendar table with every date I could ever need. (Such as from 1900-01-01 to 2099-12-31.)

    SELECT
      calendar.calendar_date,
      Count(People.created_at)
    FROM
      Calendar
    LEFT JOIN
      People
        ON Calendar.calendar_date = People.created_at
    WHERE
      Calendar.calendar_date >= '2012-05-01'
    GROUP BY
      Calendar.calendar_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql like this: SELECT *, count(*) as cc FROM manytomany GROUP
I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0;
I have a lot of SQL queries like this: SELECT o.Id, o.attrib1, o.attrib2 FROM
I have a SQL query like this: SELECT * FROM ( (SELECT name FROM
I have a sql like this: SELECT * FROM tableA WHERE column_a = sth
I have a SQL like this; select B.LoweredUserName from USER_BAYI A, aspnet_Users B, aspnet_Membership
I have a SQL query like this; SELECT * FROM Jira.customfieldvalue WHERE CUSTOMFIELD =
I have sql query like this: select a.x, a.y, sum(a.foo) as foo_sum from a
Right now, I have a SQL Query like this one: SELECT X, Y FROM
i have sql statement like this SELECT DISTINCT results_sp_08.material_number FROM results_sp_08 INNER JOIN courses

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.