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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:36:39+00:00 2026-05-13T05:36:39+00:00

Given a table that looks like this: sensor_id | time | voltage ———–+————————+———— 12292

  • 0

Given a table that looks like this:

 sensor_id |          time          |  voltage
-----------+------------------------+------------
     12292 | 2009-12-01 00:50:04-07 |       2270
     12282 | 2009-12-01 00:50:04-07 |      93774
     12192 | 2009-12-01 00:50:04-07 |       9386
     12609 | 2009-12-01 00:50:05-07 |          0
     12566 | 2009-12-01 00:50:08-07 |          0
     12659 | 2009-12-01 00:50:19-07 |        540
     12660 | 2009-12-01 00:50:19-07 |        550
     12661 | 2009-12-01 00:50:19-07 |        510
     12656 | 2009-12-01 00:50:19-07 |      30240
     12657 | 2009-12-01 00:50:19-07 |      14930
     12658 | 2009-12-01 00:50:19-07 |      17420
     11820 | 2009-12-01 00:50:26-07 |       1.38
     11832 | 2009-12-01 00:50:28-07 |      1.359
     12768 | 2009-12-01 00:50:33-07 |     636588
     13192 | 2009-12-01 00:50:34-07 |      1.401
         .                        .            .
         .                        .            .
         .                        .            .

There are times when you will get records looking like:

     12292 | 2009-12-01 00:50:04-07 |       2270
     12282 | 2009-12-01 00:50:04-07 |      93774
     12192 | 2009-12-01 00:50:04-07 |       9386
     12609 | 2009-12-01 00:50:05-07 |          0
     12566 | 2009-12-01 00:50:08-07 |          0
     12659 | 2009-12-01 00:50:19-07 |        540     *
     12659 | 2009-12-01 00:50:45-07 |        541     *
     12660 | 2009-12-01 00:50:19-07 |        550
     12661 | 2009-12-01 00:50:19-07 |        510
     12656 | 2009-12-01 00:50:19-07 |      30240
     12657 | 2009-12-01 00:50:19-07 |      14930
     12658 | 2009-12-01 00:50:19-07 |      17420
     11820 | 2009-12-01 00:50:26-07 |       1.38     #
     11832 | 2009-12-01 00:50:28-07 |      1.359
     11820 | 2009-12-01 00:50:28-07 |        1.3     #
     12768 | 2009-12-01 00:50:33-07 |     636588
     13192 | 2009-12-01 00:50:34-07 |      1.401
         .                        .            .
         .                        .            .
         .                        .            .

Notice the stared and hashed lines. Each are readings taken in the same minute, but i need only one value per minute, preferably the max value.
I tried:


select sensor_id, read_time, voltage 
from table 
where (sensor_id, read_time) 
in (select sensor_id, max(read_time) 
    from table 
    group by sensor_id);

This obviously doesn’t work, but I think I’m on the right track?


For those interested the final code looks like:


select sensor_id, date_trunc('minute', read_time), max(voltage) 
from table 
group by sensor_id, date_trunc('minute', read_time) 
order by date_trunc('minute', read_time); 
 
  • 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-13T05:36:40+00:00Added an answer on May 13, 2026 at 5:36 am

    You have to group By an expression that “defines” the one minute buckets you want the maximum values in:

    select sensor_id, DateHourMinuteFunction(read_time), Max(voltage) 
    from table 
    Group By sensor_id, DateHourMinuteFunction(read_time)
    

    Where DateHourMinuteFunction(read_time) is some function or Sql Expression in your database that will return an expression that is the same for any read_time in the same minute(i.e., it needs to strip off the seconds values)

    Can your database convert a date time to a string? If so, then at a minimum write an expression that converts it to a string, formatted as Month day year, hour, minute, second, and then strip off the seconds part…

    Assuming what you already have in the datetime column was a string, then just use substring on it…

    select sensor_id, SubString(Cast(read_time as varChar(22)), 0, 16), Max(voltage) 
    from table 
    Group By sensor_id, SubString(Cast(read_time as varChar(22)), 0, 16)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of orders that looks like this: Ticket Open Time Close
If I have an items_ordered table that looks like this: items_ordered customerid order_date item
I have a MySQL table that looks like this: id (int primary) name (text)
I have a cross reference table that looks like this: id document_id subject_id 1
I have a Table that looks like this MAC-ADDRESS | ACCESSPOINT | TIMESTAMP Data
I have a table that looks like this: ------------------------------------------------------------------- CUSTNUM (INT), ITEMNUM (INT), MONTH
I've got a sqlite table actions that looks something like this: uuid varchar (36)
Given a large input file that looks like this: 02/26/2012 08:54:38 Error:java.sql.Exception 02/26/2012 08:54:48
I have a table that looks like this CREATE TABLE `purchases` ( `id` INT(10)
I have this table that looks like this CREATE TABLE `purchases` ( `id` INT(10)

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.