Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Retrive values from different rows
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