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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:43:02+00:00 2026-06-14T19:43:02+00:00

I have a table like this: +————+——————+ |temperature |Date_time_of_data | +————+——————+ | 4.5 |9/15/2007

  • 0

I have a table like this:

+------------+------------------+
|temperature |Date_time_of_data |
+------------+------------------+
| 4.5        |9/15/2007 12:12:12|                  
| 4.56       |9/15/2007 12:14:16|
| 4.44       |9/15/2007 12:16:02|
| 4.62       |9/15/2007 12:18:23|
| 4.89       |9/15/2007 12:21:01|
+------------+------------------+

The data-set contains more than 1000 records and I want to check for the minimum variability.
For every 30 minutes if the variance of temperature doesn’t exceed 0.2, I want all the temperature values of that half an hour replaced by NULL.

  • 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-14T19:43:03+00:00Added an answer on June 14, 2026 at 7:43 pm

    Here is a SELECT to get the start of a period for every record:

    SELECT temperature,
           Date_time_of_data, 
           date_trunc('hour', Date_time_of_data)+
           CASE WHEN date_part('minute', Date_time_of_data) >= 30
                THEN interval '30 minutes'
                ELSE interval '0 minutes'
           END as start_of_period
    FROM your_table
    

    It truncates the date to hours (9/15/2007 12:12:12 to 9/15/2007 12:12:00)
    and then adds 30 minutes if the date initially had more than 30 minutes.

    Next – use start_of_period to group results and get min and max for every group:

    SELECT temperature,
           Date_time_of_data,
           max(Date_time_of_data) OVER (PARTITION BY start_of_period) as max_temp,
           min(Date_time_of_data) OVER (PARTITION BY start_of_period) as min_temp
    FROM (previou_select_here)
    

    Next – filter out the records, where the variance is more than 0.2

    SELECT temperature,
           Date_time_of_data
    FROM (previou_select_here)
    WHERE (max_temp - min_temp) <=0.2
    

    And finally update your table

    UPDATE your_table
    SET temperature = NULL
    WHERE Date_time_of_data IN (previous_select_here)
    

    You may need to correct some spelling mistakes in this queries, before they work. I havent tested them.
    And you can simplify them, if you need to.

    P.S. If you need to filter out the data with variance less than 0.2 , you can simply create a VIEW from the third SELECT with

     WHERE (max_temp - min_temp) > 0.2
    

    And use the VIEW instead of table.

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

Sidebar

Related Questions

I have table like this: +------+-------+ | user | data | +------+-------+ | 1
I have table data like this id id1 name 1 1 test1 1 1
I have a table like this Declare @Temp Table(Data VarChar(20)) Insert Into @Temp Values('F_200_100_')
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives
I have a table like this ID Name IsDeleted 1 Yogesh Null 2 Goldy
I have a table like this : +-------+------------+------+-----+---------+-------+ | Field | Type | Null
I have a table like this: ID country ------------- 1 US 2 Japan 3
I have a table like this: id | id_parent | tag_name 0 | |
I have a table like this: CREATE TABLE book_info ( book_id VARCHAR(32) not null,
I have a table like this: <table> <tr> <td> A-1 </td> <td> A-2 </td>

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.