sql - Trying to compare two consecutive records -


i using sql server 2008 , need in writing query compares 2 consecutive records.

select recorddate  sitehistory  siteid = 556145    , isrecent = 0    , isrunning = 1 order      recorddate desc 

gives me around 2000 rows looks this:

recorddate ----------------------- 2013-05-08 20:04:23.357 2013-05-08 19:45:26.417 2013-05-08 19:30:24.810  2013-05-08 19:17:22.843 2013-05-08 19:00:16.017 2013-05-08 18:44:14.230 ..... ..... 

now need compare date of each row next row , count how many times difference between 2 consecutive dates greater 15mins. come far:

;with temp as( select row_number()over(order recorddate desc)as 'row', recorddate  sitehistory  siteid = 556145 , isrecent =0 , isrunning=1 )  select count(*) count temp t1 inner join temp t2 on t2.row = t1.row+1 datediff(mm,t1.recorddate,t2.recorddate)>15 

however, doesn't give me desired. please let me know how can correct suit requirements.

logic of query correct, thing trying date difference in month change minutes in

datediff(minute, t1.recorddate, t2.recorddate) > 15 

query:

  ;with temp as(      select row_number()over(order recorddate desc)as 'row', recorddate       sitehistory       siteid = 556145 , isrecent = 0 , isrunning = 1   )   select count(*) count temp t1   inner join temp t2 on t2.row = t1.row+1   datediff(minute, t1.recorddate, t2.recorddate) > 15 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -