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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:39:22+00:00 2026-05-11T13:39:22+00:00

I have a table with timestamps. What is the proper query to get the

  • 0

I have a table with timestamps. What is the proper query to get the records counts for each minute for the last hour.

I.e. if now is 2:25, I want to know how many record were between 1:25 and 1:26, 1:26 and 1:27, and so on, so I have 60 results.

  • 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. 2026-05-11T13:39:23+00:00Added an answer on May 11, 2026 at 1:39 pm

    This will return a count of results for each minute (where you have records) in the last hour

    SELECT DATEPART(n, time_stamp) AS minute, COUNT(*) as results FROM table_name  WHERE time_stamp > DATEADD(hh, -1, GETDATE()) GROUP BY DATEPART(n, time_stamp) 

    This may return less than 60 results, depending on the data. If you have to have 60 results, the query is slightly different. This uses a Common Table Expression to generate a list of 60 numbers and a correlated sub-query to get the results for each minute:

    WITH numbers ( num ) AS (     SELECT 1 UNION ALL     SELECT 1 + num FROM numbers WHERE num < 60 ) SELECT num AS minute,     (SELECT COUNT(*) AS results     FROM table_name     WHERE DATEPART(n, time_stamp) = num     AND time_stamp > DATEADD(hh, -1, GETDATE()) FROM numbers 

    To see the results, replace DATEADD(hh, -1, GETDATE()) with DATEADD(mi, -15, GETDATE()) and you’ll get the results for the last 15 minutes and 0 for other minutes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table with over 6 million records, each with a epoch
I have a table with dates stored as unix timestamps (ints). I want my
I have a table with statistics and a field named time with Unix Timestamps.
i have a table in mysql db ( created_date). It stores timestamps (INT value).
Simply put, I have a table with, among other things, a column for timestamps.
I have a SQL table with news stories and Unix timestamps. I'd like to
I have a table with sequential timestamps: 2011-03-17 10:31:19 2011-03-17 10:45:49 2011-03-17 10:47:49 ...
I have 1 table (meetings) containing some occursion unix timestamps (dates), mostly upcoming meetings
Guys, I have a python script which builds up a MySQL table with timestamps
I have a table that has a START_DATE and an END_DATE column. I want

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.