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 sql question

Re: a sql question

From: David Portas <REMOVE_BEFORE_REPLYING_dportas_at_acm.org>
Date: 5 Mar 2007 14:53:52 -0800
Message-ID: <1173135232.716997.111490@t69g2000cwt.googlegroups.com>


On 5 Mar, 22:36, "z..._at_hotmail.com" <z..._at_hotmail.com> wrote:
> Hi,
>
> Oracle 10g.
> I have a table with data like this:
>
> id val
> 1 100
> 2 101
> 3 200
> 4 300
>
> and I want a query which displays the result of "val" minus the
> "previous val", order by id, something like:
>
> id computed_value
> 2 1
> 3 99
> 4 100
>
> How do I accomplish that using sql (not pl/sql)?
>
> TIA
> Guang

SELECT t1.id, t1.val-t2.val AS computed_value FROM tbl AS t1, tbl AS t2
WHERE t1.id-1 = t2.id;

--
David Portas
Received on Mon Mar 05 2007 - 16:53:52 CST

Original text of this message

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