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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:04:02+00:00 2026-05-15T23:04:02+00:00

I have the following query: SELECT timestamp, COUNT(*) FROM table GROUP BY timestamp But

  • 0

I have the following query:

  SELECT timestamp,
         COUNT(*)
    FROM table
GROUP BY timestamp

But some timestamps do not show up because there is no data. Here’s an example

1:00:00 |  3
1:00:02 | 17
1:00:03 |  2

Notice that 1:00:01 is missing. Is there a way to make the 1:00:01 | 0 appear in the result?

  • 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-15T23:04:03+00:00Added an answer on May 15, 2026 at 11:04 pm

    MySQL doesn’t have recursive functionality, so you’re left with using the NUMBERS table trick –

    1. Create a table that only holds incrementing numbers – easy to do using an auto_increment:

      DROP TABLE IF EXISTS `example`.`numbers`;
      CREATE TABLE  `example`.`numbers` (
        `id` int(10) unsigned NOT NULL auto_increment,
         PRIMARY KEY  (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
      
    2. Populate the table using:

      INSERT INTO NUMBERS
        (id)
      VALUES
        (NULL)
      

      …for as many values as you need.

    3. Use DATE_ADD to construct a list of times, increasing the seconds based on the NUMBERS.id value:

      SELECT x.*
        FROM (SELECT DATE_FORMAT(DATE_ADD('2010-01-01', INTERVAL n.id - 1 SECOND), '%T') 
                FROM numbers n) x
      
    4. LEFT JOIN onto your table of data based on the time portion:

         SELECT x.ts AS timestamp,
                COALESCE(COUNT(y.timestamp), 0) AS cnt
           FROM (SELECT DATE_FORMAT(DATE_ADD('2010-01-01', INTERVAL n.id - 1 SECOND), '%T') AS ts
                   FROM numbers n) x
      LEFT JOIN TABLE y ON y.timestamp = x.ts
       GROUP BY x.ts
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have the following (shortened query): SELECT `Statistics`.`StatisticID`, COUNT(DISTINCT `Flags`.`FlagType`) AS `FlagCount` FROM `Statistics`
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I'm having trouble with the following query: SELECT costingjobtimes.TimeStamp, costingdepartment.DeptDesc, costingemployee.Name, costingjobtimes.TimeElapsed FROM costingemployee
I have a select query that currently produces the following results: Description Code Price
I have the following Java 6 code: Query q = em.createNativeQuery( select T.* +
I have the following query which works fine with MySQL but refuses to work
I have a MySQL table like the following: date count 2010-01-01 5 2010-01-02 6

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.