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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:09:52+00:00 2026-06-01T17:09:52+00:00

Here is my SQL: SELECT COUNT(id), CONCAT(YEAR(created_at), ‘-‘, MONTH(created_at), ‘-‘, DAY(created_at)) FROM my_table GROUP

  • 0

Here is my SQL:

SELECT 
  COUNT(id),
  CONCAT(YEAR(created_at), '-', MONTH(created_at), '-', DAY(created_at))
FROM my_table
GROUP BY YEAR(created_at), MONTH(created_at), DAY(created_at)

I want a row to show up even for days where there was no ID created. Right now I’m missing a ton of dates for days where there was no activity.

Any thoughts on how to change this query to do that?

  • 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-01T17:09:53+00:00Added an answer on June 1, 2026 at 5:09 pm

    The way to do it in one query:

    SELECT COUNT(my_table.id) AS total,
     CONCAT(YEAR(dates.ddate), '-', MONTH(dates.ddate),  '-', DAY(dates.ddate))
    FROM (
       -- Creates "on the fly" 65536 days beginning from 2000-01-01 (179 years)
       SELECT DATE_ADD("2000-01-01", INTERVAL (b1.b + b2.b + b3.b + b4.b + b5.b + b6.b + b7.b + b8.b + b9.b + b10.b + b11.b + b12.b + b13.b + b14.b + b15.b + b16.b) DAY) AS ddate FROM
       (SELECT 0 AS b UNION SELECT 1) b1,
       (SELECT 0 AS b UNION SELECT 2) b2,
       (SELECT 0 AS b UNION SELECT 4) b3,
       (SELECT 0 AS b UNION SELECT 8) b4,
       (SELECT 0 AS b UNION SELECT 16) b5,
       (SELECT 0 AS b UNION SELECT 32) b6,
       (SELECT 0 AS b UNION SELECT 64) b7,
       (SELECT 0 AS b UNION SELECT 128) b8,
       (SELECT 0 AS b UNION SELECT 256) b9,
       (SELECT 0 AS b UNION SELECT 512) b10,
       (SELECT 0 AS b UNION SELECT 1024) b11,
       (SELECT 0 AS b UNION SELECT 2048) b12,
       (SELECT 0 AS b UNION SELECT 4096) b13,
       (SELECT 0 AS b UNION SELECT 8192) b14,
       (SELECT 0 AS b UNION SELECT 16384) b15,
       (SELECT 0 AS b UNION SELECT 32768) b16
     ) dates
     LEFT JOIN my_table ON dates.ddate = my_table.created_at
     GROUP BY dates.ddate
     ORDER BY dates.ddate
    

    The next code is only necessary if you want to test and don’t have the “my_table” indicated on the question:

    create table `my_table` (
        `id` int (11),
        `created_at` date 
    ); 
    insert into `my_table` (`id`, `created_at`) values('1','2000-01-01');
    insert into `my_table` (`id`, `created_at`) values('2','2000-01-01');
    insert into `my_table` (`id`, `created_at`) values('3','2000-01-01');
    insert into `my_table` (`id`, `created_at`) values('4','2001-01-01');
    insert into `my_table` (`id`, `created_at`) values('5','2100-06-06');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my SQL SELECT items.name, items.id, items.price, COUNT(cart_items.itemId) AS quantity FROM `cart_items` LEFT
Here's my current SQL statement: SEARCH_ALBUMS_SQL = SELECT * FROM albums WHERE title LIKE
See the tables structure here. I have this sql: SELECT `feed_entries` . * FROM
Here is my query: SELECT count(*) FROM table_testcase_execution WHERE campaign_session_id = any(SELECT campaign_session_id FROM
I am using mysql. Here is my sql SELECT LIMIT 1 users.id, COUNT(events.id) AS
I can easily locate the rows I want with these sql statements: SELECT COUNT(*)
I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr) from tpoll_answer
Let's say I have this SQL: SELECT p.ParentId, COUNT(c.ChildId) FROM ParentTable p LEFT OUTER
I want get the value from Exec(@sql) and assign to @Rowcount(int) Here is my

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.