Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to compare values within a table - SQL

Re: How to compare values within a table - SQL

From: <shiling_at_math.wayne.edu>
Date: Sun, 27 Jun 1999 00:07:24 GMT
Message-ID: <7l3pvo$ab3$1@nnrp1.deja.com>


For this type of problem, you may do a self-join or Cartesian product join.

According to your result, your data and your request seems like,

 id year month amount

 1    1999    3      10
 1    1999    4      10
 1    1999    5      10
 2    1999    3      10
 2    1999    4      25
 3    1999    3      10
 3    1999    4      25

when (the amount of month 4 - the amount of month 3)/the amount of month 3> 50%?

Base on this understand, SQL statement looks like,

select a.id from t1 a, t1 b
 where a.month =3
  and b.month =4
  and a.id=b.id
  and (b.amount - a.amount)/a.amount >0.5

In article <3775022f.0_at_ecn.ab.ca>,
  suisum_at_ecn.ab.ca () wrote:
> MyTable
> =======
>
> id year month amount
> 1 1999 3 10
> 1 1999 4 10
> 1 1999 5 10
> 2 1999 3 10
> 2 1999 4 25
> 3 1999 3 10
> 3 1999 5 10
>
> How to list out the IDs when (the amount of month 3 - the amount of
month
> 4) > 50%?
>
> With the above data, I want to have the following output:
>
> id
> ==
> 2
> 3
>
> --
> Best regards,
>

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't. Received on Sat Jun 26 1999 - 19:07:24 CDT

Original text of this message

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