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 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

Ask A Question

Stats

  • Questions 148k
  • Answers 148k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The idea is to build a list of all original… May 12, 2026 at 9:20 am
  • Editorial Team
    Editorial Team added an answer I've tracked down the problem and as suggested it was… May 12, 2026 at 9:20 am
  • Editorial Team
    Editorial Team added an answer Customer's machine have Visual Studio 2005 installed. Adobe SVG Viewer… May 12, 2026 at 9:20 am

Related Questions

I suppose most of the developers have an idea of multi-layer architecture. We have
I have an idea for how to solve this problem, but I wanted to
Current, I've got a stored procedure that has a main goal of doing a
So I've looked at this use of the freebase API and I was really

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.