How to find consecutive records below a certain value?

Answered How to find consecutive records below a certain value?

  • Tuesday, December 06, 2011 4:20 PM
     
     
    I have a table with hundreds of millions of rows in the following structure: case_id (int), channel_index (int), start_time (datetime), value (float), duration (smallint) I need to create a query that will return the case_ids where a channel_index has a value < a specific amount for 3 consecutive minutes. We have the duration column which contains the calculated number of seconds between that record and the next record to help speed up the query but I cannot seem to find a non brute force way to accomplish this. For example: I thought there might be a way to have a running sum over value < 60 or something like that but it needs to reset when the value is > 60. Any suggestions?

All Replies