sql - How to find a gap in a time ordered table where a given column does not have a certain value for a specified interval -


I have a large desk (millions of rows) where I need to find groups of records based on the presence of a specific column The value and where a specified 'timeout' has not happened, I understand that in the entire table it has to find out where this 'timeout' interval has happened.

Example table:

 + ---------------- + ------ + | Time | Base | + ---------------- + ------ + | 1245184797.064 | One | | 1245184802.020 | One | | 1245184807.103 | B | 1245184812.089 | B | 1245184816.831 | B | 1245184821.856 | One | | 1245184821.856 | One | | 1245184855.903 | One | | 1245184855.903 | B | 1245184858.362 | B | 1245184858.362 | B | 1245184860.360 | One | | 1245184860.360 | One | | 1245184862.174 | One | | 1245184862.174 | B | 1245185001.480 | B | 1245185417.556 | One | | 1245185417.844 | One | | 124518541996060 B | 1245185420.181 | B + ---------------- + ------ + 

Looking at this set, how can I quickly get points in the table where the base = This has not happened for a few seconds (say 5).

To boil it, my purpose is to find the spaces of the record, where the base = has been done continuously without a time.

I think this will help you:

  SELECT * FROM (SELECT t1. [Time], t1.time - (Select MAX (time) my_table T2 from WHERE t2. Time & lt; t1.time and t2.base = 'a') my_table t1 WHERE t1.base = 'a 'Timed out) d WHERE timeout & gt; 5  

and do not forget to make the index of this query more effective:

Create idx_my_table_time_base from time to time on my_table (time, basis)

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -