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: Rodrigo De León <rdeleonp_at_gmail.com>
Date: Mon, 18 Jun 2007 02:33:42 -0000
Message-ID: <1182134022.124419.189120@g4g2000hsf.googlegroups.com>


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. Received on Sun Jun 17 2007 - 21:33:42 CDT

Original text of this message

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