MySQL Forums
Forum List  »  Newbie

Re: scanning for data gaps in time series
Posted by: laptop alias
Date: July 16, 2011 05:12AM

What about...

SELECT a.datetime starttime
     , b.datetime stoptime
     , TIMEDIFF(b.datetime,a.datetime) gap
  FROM
     ( SELECT x.*
            , COUNT(*) rank
         FROM as_follows x
         JOIN as_follows y
           ON y.datetime <= x.datetime
        GROUP 
           BY x.datetime
     ) a
  JOIN
     ( SELECT x.*
            , COUNT(*) rank
         FROM as_follows x
         JOIN as_follows y
           ON y.datetime <= x.datetime
        GROUP 
           BY x.datetime
     ) b
    ON b.rank = a.rank + 1
   AND b.datetime > ADDDATE(a.datetime,INTERVAL 2 MINUTE);

?

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.