oracle11g - if clause in Oracle SQL -


i need query in oracle sql. here table example:

time                      var '2015.07.08 01:00:01'     0.1 '2015.07.08 01:00:02'     0.15 '2015.07.08 01:00:03'     0.22 '2015.07.08 01:00:04'     0.13 '2015.07.08 01:00:05'     0 '2015.07.08 01:00:06'     0.1 '2015.07.08 01:00:07'     0.02 '2015.07.08 01:00:08'     0 '2015.07.08 01:00:20'     0.1 

now need time differences object x+1 , x if var equal 0. example want see output in seconds:

1   # '2015.07.08 01:00:06' - '2015.07.08 01:00:05' 12  # '2015.07.08 01:00:20' - '2015.07.08 01:00:08' 

how statement for: if var==0 calculate time(row+1) - time(row). help.

use lag previous record:

select (time - time_before) * 24 * 60 * 60 (   select     time,      var,      lag(var) on (order time) var_before,     lag(time) on (order time) time_before   mytable ) var_before = 0 order time; 

oops, overly complicated. use lead next record instead :-)

select (lead(time) on (order time) - time) * 24 * 60 * 60 mytable var = 0 order time; 

the first query bit more precise, though. if last record contains 0, not considered query 1, because there no later record. second query, however, return null, because lead(time) results in null when there no following record. it's decide whether bothers or not.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -