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: Retrive values from different rows

Re: Retrive values from different rows

From: <sviluppo.sw_at_gmail.com>
Date: Mon, 18 Jun 2007 12:21:00 -0700
Message-ID: <1182194460.095454.253320@u2g2000hsc.googlegroups.com>


On 18 Giu, 04:33, Rodrigo De León <rdele..._at_gmail.com> wrote:
> On Jun 17, 9:27 am, sviluppo..._at_gmail.com wrote:
>
> > In other words this must be the result:
> > ID ART QTA REASON VAL
> > 1 A 10 W 10
> > 2 A -2 C 8
> > 3 A 3 PO 11
> > 4 A -4 C 7
> > 5 B 5 W 5
> > 6 B -2 C 3
> > 7 B -4 C -1
> > 8 B 5 PO 4
> > 9 C 5 W 5
> > 10 D 7 W 7
>
> I'm not quite following this.
>
> Is ID supposed to state the order of the records? If so:
>
> SELECT ID, art, qta, reason
> , CASE
> WHEN reason = 'W'
> THEN qta
> ELSE (SELECT SUM (qta)
> FROM thetable
> WHERE art = t.art AND ID <= t.ID)
> END AS val
> FROM thetable t
> ORDER BY ID
>
> Q: What happens when, for example, there's another 'W' REASON for ART
> 'A'? Can that happen?
>
> Good luck.

Perfect! I've already put in production your tips and it works great. It's *exactly* what I was looking for!
Thank you very much. Received on Mon Jun 18 2007 - 14:21:00 CDT

Original text of this message

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