| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: a difficult SQL request
Sounds like you can use analytic functions, lead/lag in a view. Read up on
analytic functions and window clauses for lag, but here is an example, if I
understand your question correctly. Here is lag is only looking at the
previous row.
SQL> select to_char(c_time,'hh:mi'),volume from data_collector;
TO_CH VOLUME
----- ----------
12:01 1 12:02 2 12:03 3 12:04 3 12:05 3 12:06 3 12:07 3 12:08 3 12:09 3 12:10 3 12:11 3
11 rows selected.
SQL> select * from
(
select
to_char(c_time,'hh:mi'),
volume,
lag (volume) over (order by c_time) previous_vol
from data_collector
)
where volume = previous_vol;
TO_CH VOLUME PREVIOUS_VOL
----- ---------- ------------
12:04 3 3 12:05 3 3 12:06 3 3 12:07 3 3 12:08 3 3 12:09 3 3 12:10 3 3 12:11 3 3Received on Sun Feb 23 2003 - 09:15:51 CST
![]() |
![]() |