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

The Archive Base Latest Questions

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

I’ve got a table in a database that stores log data by time. For

  • 0

I’ve got a table in a database that stores log data by time. For one day there can be a million rows in the db. The times are not at any regular interval. It has several indexes, including the time. What I want to do is build a query that will return a set of rows with one row per time interval. For example, I could do a query to return 1 row every 15 minutes for a day. This would return 24*60=96 rows. Each row returned would actually be the nearest row in the db prior to the interval requested (since the data in the database will not equal the requested interval).

I am at a loss for how to do it. I can’t just query all rows for a particular set of indexes and time interval, as it would load more than a gigabyte of data into memory, which is too slow. Is there any efficient way to do this using SQL. I’m using a MySQL database. I would be open to changing the table indexes/etc…

TIME

11:58
12:03
12:07
12:09
12:22
12:27
12:33
12:38
12:43
12:49
12:55

If I wanted to query this for a 15 minute interval from 12:00 to 1:00, I’d get back:

11:58 (nearest 12:00)
12:09 (nearest 12:15)
12:27 (nearest 12:30)
12:43 (nearest 12:45)
12:55 (nearest 1:00) 

If it makes it any easier, I can also store the time as a number (i.e. ms since 1970). In the above query, this would then be an interval of 900000 ms.

  • 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:50:47+00:00Added an answer on June 4, 2026 at 2:50 am

    So, I had thought something like:

    SELECT 
      MIN(timeValue)
    FROM e
    GROUP BY (to_seconds(timeValue) - (to_seconds(timeValue) % (60 * 5)))
    

    ..would do it for you, but this only returns the MIN(timeValue) over the whole table. It works if the seconds rounded to the nearest 5 min is in its own col.

    See SQL Fiddle

    Edit per Andiry, this works: ( http://sqlfiddle.com/#!2/bb870/6 )

    SELECT MIN(t)
    FROM e
    GROUP BY to_seconds(t) DIV (60 * 5)
    

    But this just gives one row: ( http://sqlfiddle.com/#!2/bb870/7 )

    SELECT MIN(t)
    FROM e
    GROUP BY to_seconds(t) - (to_seconds(t) % (60 * 5))
    

    Anyone know why?

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
i got an object with contents of html markup in it, for example: string

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.