Need to get difference of alternative consecutive rows in a table using Sql query -


could 1 me solving following query.

my table:

pkid | datetime ------------------  1     2011-07-01 09:33:00  5     2011-07-01 14:01:00  7     2011-07-01 14:06:00  9     2011-07-01 19:18:00 

i need difference of times between first , second row, third , fourth row.

result:

(14:01:00 - 09:33:00) (19:18:00 - 14:06:00) 

regards, bharath

you can use lag function in oracle follow -

select *   (      select t_1.*,datetime - lag(datetime , 1, 0) on (order pkid), rownum c_1        (                select pkid , datetime my_table order pkid        ) t_1  ) c_1%2 = 0 

i think can understand one.. explanation not required .. right??


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -