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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:06:11+00:00 2026-05-31T06:06:11+00:00

I have a mysql database with which contains data in 5 minute bins. I’d

  • 0

I have a mysql database with which contains data in 5 minute bins. I’d like to create hourly average of the data starting on the half hour.
By using mysql built-in group by:

select date,AVG(AE) from mytable group by date(date),HOUR(date);    

would compute average value from say, 01:00 to 02:00. Instead I would like hourly averages to be computed from 00:30 to 01:30, were the value would then be the hourly average at 01:00.

This query fail when a new day starts:

select date, AVG(AE) from mytable group by date(date), HOUR( date ) + FLOOR( MINUTE( date ) / 30 );
+---------------------+------------------+
| date                | AVG(AE)          |
+---------------------+------------------+
| 1997-01-01 22:30:00 |               23 | 
| 1997-01-01 23:30:00 |             28.3 | 
| 1997-01-02 00:00:00 | 20.1333333333333 | 
| 1997-01-02 00:30:00 |             29.3 | 
| 1997-01-02 01:30:00 | 27.5666666666667 | 
| 1997-01-02 02:30:00 | 43.4166666666667 | 

which is the closest I’ve gotten 🙂

In another post ( https://stackoverflow.com/a/6560742/1142735 ) it was suggested that GROUP BY FLOOR(MOD((mytimestamp-1800)/3600)) would create intervals starting on the half hour if timestamp was used. I am using datetime.

Thanks

Paul

  • 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-31T06:06:12+00:00Added an answer on May 31, 2026 at 6:06 am

    Anything that uses the DATE() function will fail to correctly group the interval 23:30 - 00:30.

    Use:

    FLOOR((UNIX_TIMESTAMP(date) - 1800) / 3600)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MySQL database which contains some data,it interacts with JSP pages,the thing
I have a mysql database which as one of the fields contains a html
i have a large mysql database table in which one column contains values ranging
Greetings friends, In my MySQL database, I have 'MAB' table which contains information about
I have MySQL database, where I store the following BLOB (which contains JSON object)
I have a mysql database which contains several tables. At the moment i'm using
I have a table with a field which contains strings in my MySQL database.
I have read-only access to a remote MySQL database, which contains a very large
I have read-only access to a remote MySQL database, which contains a very large
I have a mysql database which has grown to over 200 tables in it.

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.