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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:55:12+00:00 2026-05-23T22:55:12+00:00

I’m working on a ECG data that basically has the following schema Col 1

  • 0

I’m working on a ECG data that basically has the following schema

Col 1 = TIMESTAMP
Col 2 = PATIENTID
Col 3 = ECGVALUE

Now, I’m trying to write a SQL statement that should be able to select all the rows that satisfy the following condition

Row index >= n and TIMESTAMP of xth row <= TIMESTAMP of nth row + offset

To explaing it further, let say I’ve following data in my database

1.1 ANON 1.1
1.3 ANON 2.3
3.5 ANON 4.3
5.0 ANON 6.5
6.3 ANON 7.5
7.9 ANON 8
8.6 ANON 9.4

Now, I want to select the data from 3rd row till 3 seconds of data has been collected, which means that my resultset should have

3.5 ANON 2.3 *//3rd row till TIMESTAMP <= 3.5 + 3 <= 6.5*
1.3 ANON 2.3
3.5 ANON 4.3
5.0 ANON 6.5
6.3 ANON 7.5

Last two rows are neglected as difference between TIMESTAMP of first and last cannont go beyond 3. So If I go back to my condition, which is

Row index >= n and TIMESTAMP of xth row <= TIMESTAMP of nth row + offset

Here,

n: nth row from where data must be selected
x: Any arbitary row in result set
offset: Maximum difference between first and last TIMESTAMP of result set.

I’ve written a working SQL statement for the above condition, but I think its not that much optimized as I’m new to SQL.

SELECT TIMESTAMP, ECGVALUE
FROM
(
    SELECT TIMESTAMP, ECGVALUE, ROW_NUMBER() OVER() AS RN
    FROM EKLUND.DEV_RAWECG
)
WHERE RN >= n AND TIMESTAMP <=
(
    SELECT TIMESTAMP FROM
    (
        SELECT TIMESTAMP, ROW_NUMBER() OVER() AS TM
    )
    WHERE TM = n
) + offset;
  • 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-23T22:55:12+00:00Added an answer on May 23, 2026 at 10:55 pm

    The code will look a lot cleaner if you use a common table expression, as follows:

    WITH rownums(TIMESTAMP, ECGVALUE, RN) AS (
        SELECT TIMESTAMP, ECGVALUE, ROW_NUMBER() OVER(ORDER BY TIMESTAMP) AS RN
        FROM EKLUND.DEV_RAWECG
    )
    SELECT allrows.TIMESTAMP, allrows.ECGVALUE, allrows.RN
    FROM rownums allrows
         CROSS JOIN rownums rown
    WHERE rown.RN = n
          AND allrows.RN >= n
          AND rown.TIMESTAMP + offset >= allrows.TIMESTAMP;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.