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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Any way to do this in straight SQL?

Re: Any way to do this in straight SQL?

From: jaromir nemec <jaromir_at_db-nemec.com>
Date: Thu, 8 Dec 2005 13:08:51 +0100
Message-ID: <0e1f01c5fbf0$28530760$3c02a8c0@JARAWIN>


Hi List,

> There is probably a more elegant way to do it, ...

I guess the IGNORE NULLS clause (10g) was introduced with the intention to avoid the MAX .. OVER() trick to eliminate NULLS.

I'd propose something like this ..

SQL> select history_id,
  2 history_sequence,
  3 history_status,
  4 case when history_status != 'PROCESSED' then   5 history_balance
  6 else -- use history_balance from last non processed status   7 last_value(case when history_status != 'PROCESSED' then history_balance end ignore nulls)
  8 over (partition by history_id order by history_sequence)   9 end as history_balance
 10 from history
 11 order by history_id, history_sequence;

HISTORY_ID HISTORY_SEQUENCE HISTORY_STATUS HISTORY_BALANCE

---------- ---------------- -------------------- ---------------
         1              123 HISTORY 1                         10
         1              128 PROCESSED                         10
         1              130 PROCESSED                         10
         1              131 HISTORY 8                         15
         1              145 PROCESSED                         15

Elapsed: 00:00:00.57

Regards,

Jaromir
----- Original Message -----
From: "Kristian Myllymäki" <kristian_at_kmja.com> To: <ryan_gaffuri_at_comcast.net>
Cc: <oracle-l_at_freelists.org>
Sent: Wednesday, December 07, 2005 11:56 PM Subject: Re: Any way to do this in straight SQL?

>

--
http://www.freelists.org/webpage/oracle-l
Received on Thu Dec 08 2005 - 06:14:59 CST

Original text of this message

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