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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:41:02+00:00 2026-06-19T02:41:02+00:00

i have a sliding window problem. specifically, i do not know where my window

  • 0

i have a sliding window problem. specifically, i do not know where my window should start and where it should end. i do know the size of my interval/window.

i need to find the start/end of the window that delivers the best (or worst, depending on how you look at it) case scenario.

here is an example dataset:

 value  | tstamp
 100    | 2013-02-20 00:01:00
 200    | 2013-02-20 00:02:00
 300    | 2013-02-20 00:03:00
 400    | 2013-02-20 00:04:00
 500    | 2013-02-20 00:05:00
 600    | 2013-02-20 00:06:00
 500    | 2013-02-20 00:07:00
 400    | 2013-02-20 00:08:00
 300    | 2013-02-20 00:09:00
 200    | 2013-02-20 00:10:00
 100    | 2013-02-20 00:11:00

let’s say i know that my interval needs to be 5 minutes. so, i need to know the value and timestamps included in the 5 minute interval where the sum of ‘value’ is the highest. in my above example, the rows from ‘2013-02-20 00:04:00’ to ‘2013-02-20 00:08:00’ would give me a sum of 400+500+600+500+400 = 2400, which is the highest value over 5 minutes in that table.

i’m not opposed to using multiple tables if needed. but i’m trying to find a “best case scenario” interval. results can go either way, as long as they net the interval. if i get all data points over that interval, it still works. if i get the start and end points, i can use those as well.

i’ve found several sliding window problems for SQL, but haven’t found any where the window size is the known factor, and the starting point is unknown.

  • 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-19T02:41:03+00:00Added an answer on June 19, 2026 at 2:41 am
    SELECT  *,
            (
            SELECT  SUM(value)
            FROM    mytable mi
            WHERE   mi.tstamp BETWEEN m.tstamp - '5 minute'::INTERVAL AND m.tstamp
            ) AS maxvalue
    FROM    mytable m
    ORDER BY
            maxvalue DESC
    LIMIT   1
    

    In PostgreSQL 11 and above:

    SELECT  SUM(value) OVER (ORDER BY tstamp RANGE '5 minute' PRECEDING) AS maxvalue,
            *
    FROM    mytable m
    ORDER BY
            maxvalue DESC
    LIMIT   1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a sliding panel that should appear in the center of any
I have a sliding JS menu that opens when you click the noty_menu link,
I have two divs that are sliding from right to left. I am having
I am writing a sliding window compression algorithm (LZ77) that searches for phrases in
I'm writing an algorithm in C++ that scans a file with a sliding window,
I have added the code that working for right to left sliding perfectly but
I have a list of numbers and I'd like to select a sliding window
Is there any built in library for sliding a window (custom size) over an
In Clojure, what would be the nicest way to have a sliding window over
I'm trying to figure out some sliding window stats on my users. I have

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.