Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: a difficult SQL request

Re: a difficult SQL request

From: Buck Turgidson <jc_va_at_hotmail.com>
Date: Sun, 23 Feb 2003 15:15:51 GMT
Message-ID: <HA56a.58007$P1.3687205@news1.east.cox.net>


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            3
Received on Sun Feb 23 2003 - 09:15:51 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US