Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to do this trick ?
Hi,
here is the solution for your problem:
select min(a.empno) empno, 0 Diff from emp a
union
select b.empno empno, b.empno-c.empno Diff
from emp b, emp c
where
c.empno=
(select max(d.empno)
from emp d
where b.empno-d.empno>0
)
order by empno;
Result:
EMPNO DIFF
--------- ---------
7369 0 7499 130 7521 22 7566 45 7654 88 7698 44 7782 84 7839 57 7844 5 7900 56 7902 2 7934 32
Reg Kai
Norazman Abu Sahir <norazman_at_ti.com> wrote in article
<38069C0B.80DF880E_at_ti.com>...
> Hi,
> I have a table with one colum. When I do a select below are the data.
>
> SQL> SELECT MYNUMBER FROM TESTING;
>
> MYNUMBER
> ----------
> 1
> 3
> 5
> 10
>
> What I would like to do is how to display a different betwen a row value
> with a previous row value.
> Something like this:
>
> MYNUMBER DIFF
> ---------- -------
> 1 0
> 3 2
> 5 2
> 10 5
>
> Have any idea?
> TIA
>
>
Received on Fri Oct 15 1999 - 03:34:05 CDT
![]() |
![]() |