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

The Archive Base Latest Questions

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

I have a datetime query that works qreat: $q=SELECT COUNT(blocked) AS sum_blocked, DATE(created) AS

  • 0

I have a datetime query that works qreat:

$q="SELECT COUNT(blocked) AS sum_blocked, DATE(created) AS date_label ".
   "FROM sms_subscribers WHERE blocked=0 GROUP BY DATE(created)";

The only problem is I can not figure out how / if I can fill dates with zero results with zero or null.

ie; if there are 5 records for 2011-08-25 and 7 records for 2011-08-27, I would like the result to return 5, 0, 7 or 5, null, 7

Any help would be greatly appreciated!

  • 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-24T22:18:03+00:00Added an answer on May 24, 2026 at 10:18 pm

    You could create an additional table with number of days and join two tables. Here it is an example, it works for specified month –

    CREATE TABLE days (
      number INT(11) NOT NULL
    );
    
    CREATE TABLE sms_subscribers (
      id INT(11) NOT NULL AUTO_INCREMENT,
      created DATETIME DEFAULT NULL,
      PRIMARY KEY (id)
    );
    
    INSERT INTO days VALUES 
      (1), (2), (3), (4), (5), (6), (7), (8), (9), (10),
      (11), (12), (13), (14), (15), (16), (17), (18), (19), (20),
      (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31);
    
    INSERT INTO sms_subscribers VALUES 
      (1, '2011-08-25 08:35:27'),
      (2, '2011-08-11 08:35:30'),
      (3, '2011-08-06 08:35:35'),
      (4, '2011-06-06 08:35:40'),
      (5, '2011-06-19 08:35:47'),
      (6, '2011-06-01 08:35:53'),
      (7, '2011-08-28 08:36:02'),
      (8, '2011-08-25 08:57:58');
    
    
    SELECT d.number, COUNT(t.created) FROM days d
      LEFT JOIN (SELECT * FROM sms_subscribers
                  WHERE YEAR(created) = 2011 AND MONTH(created) = 8) t -- Specify year and monts here
        ON DAYOFMONTH(t.created) = d.number
    WHERE
      d.number <= DAYOFMONTH(LAST_DAY('2011-08-01')) -- Specify any day in the specified month, it will help to found out max number of days in the month
    GROUP BY d.number;
    
    +--------+------------------+
    | number | COUNT(t.created) |
    +--------+------------------+
    |      1 |                0 |
    |      2 |                0 |
    |      3 |                0 |
    |      4 |                0 |
    |      5 |                0 |
    |      6 |                1 |
    |      7 |                0 |
    |      8 |                0 |
    |      9 |                0 |
    |     10 |                0 |
    |     11 |                1 |
    |     12 |                0 |
    |     13 |                0 |
    |     14 |                0 |
    |     15 |                0 |
    |     16 |                0 |
    |     17 |                0 |
    |     18 |                0 |
    |     19 |                0 |
    |     20 |                0 |
    |     21 |                0 |
    |     22 |                0 |
    |     23 |                0 |
    |     24 |                0 |
    |     25 |                2 |
    |     26 |                0 |
    |     27 |                0 |
    |     28 |                1 |
    |     29 |                0 |
    |     30 |                0 |
    |     31 |                0 |
    +--------+------------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query which involves a table from another server: select count(serialno), max(convert(varchar(10),Crtd_DateTime,101))
I have objects that has a DateTime property, how can i query for the
I have a datetime field like that. <field name=rel_date type=date indexed=true stored=true default=NOW multiValued=false/>
I have a query that calculates the hours worked from dates which includes times.
I have a linq query that works just fine but when StyleCop is run
I'm having some trouble with MySql right now. I have an query that works
I have to compare three dates in linq query (datetime a < datetime b
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
I have a datetime column in db that I want to transform into a
I have a DataTable with a DateTime column, DateCol, that can be DBNull. The

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.