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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:27:25+00:00 2026-05-11T21:27:25+00:00

Problem: I have a database of sensor readings with a timestamp for the time

  • 0

Problem:

I have a database of sensor readings with a timestamp for the time the sensor was read. Basically it looks like this:

Sensor | Timestamp | Value

Now I want to make a graph out of this data and I want to make several different graphs. Say I want one for the last day, one for the last week and one for the last month. The resolution of each graph will be different so for the day-graph the resolution would be 1 minute. For the week graph it would be one hour and for the month graph it would be one day, or quarter of a day.

So I would like an output that is the average of each resolution (eg. Day = Average over the minute, Week = Average over the hour and so on)

Ex:

Sensor | Start | End | Average

How do I do this easily and quickly in mySQL? I suspect it invoves creating a temporary table or sorts and joining the sensor data with that to get the average values of the sensor? But my knowledge of mySQL is limited at best.

Is there a really clever way to do this?

  • 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-11T21:27:25+00:00Added an answer on May 11, 2026 at 9:27 pm
    SELECT  DAY(Timestamp), HOUR(Timestamp), MINUTE(Timestamp), AVG(value)
    FROM    mytable
    GROUP BY
            DAY(Timestamp), HOUR(Timestamp), MINUTE(Timestamp) WITH ROLLUP
    

    WITH ROLLUP clause here produces extra rows with averages for each HOUR and DAY, like this:

    SELECT  DAY(ts), HOUR(ts), MINUTE(ts), COUNT(*)
    FROM    (
            SELECT  CAST('2009-06-02 20:00:00' AS DATETIME) AS ts
            UNION ALL
            SELECT  CAST('2009-06-02 20:30:00' AS DATETIME) AS ts
            UNION ALL
            SELECT  CAST('2009-06-02 21:30:00' AS DATETIME) AS ts
            UNION ALL
            SELECT  CAST('2009-06-03 21:30:00' AS DATETIME) AS ts
            ) q
    GROUP BY
            DAY(ts), HOUR(ts), MINUTE(ts) WITH ROLLUP
    
    2, 20, 0, 1
    2, 20, 30, 1
    2, 20, NULL, 2
    2, 21, 30, 1
    2, 21, NULL, 1
    2, NULL, NULL, 3
    3, 21, 30, 1
    3, 21, NULL, 1
    3, NULL, NULL, 1
    NULL, NULL, NULL, 4
    

    2, 20, NULL, 2 here means that COUNT(*) is 2 for DAY = 2, HOUR = 20 and all minutes.

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

Sidebar

Related Questions

This is probably the most classic database problem. I have an E-commerce software solution
Problem: I have an address field from an Access database which has been converted
We have a common problem of moving our development SQL 2005 database onto shared
I have a simple problem when querying the SQL Server 2005 database. I have
Problem I have timestamped data, which I need to search based on the timestamp
I have this problem where I can't get my dynamic data web app to
Imagine the following problem: You have a database containing about 20,000 texts in a
We have a couple of mirrored SQL Server databases. My first problem - the
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem: We have a web app that calls some web services asynchronously (from the

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.