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: Calculate median with ORACLE??

Re: Calculate median with ORACLE??

From: Rob Johnson <jaws_at_southwind.net>
Date: 1997/02/22
Message-ID: <330F7F53.666D@southwind.net>#1/1

Here's how you do it:

Where the table is table1 and the column is col1:

select avg(a.col1)
from
table1 a, table1 b
having
(ABS(SUM(SIGN(a.col1 - b.col1))) - SUM(DECODE(b.col1,a.col1,1,0)) <= 0) group by a.col1

I tested this on all cases I could think of, and it always worked. For example, if you have a set of values like (1,2,3,4) this statement returns 2.5, the average of 2 and 3.

Sylvain Grenier wrote:
>
> Hi,
>
> I recently had a request to calculate some statistics on a Oracle table
> values. I have to calculate minimum, maximum, average and median. The
> three first are not to complicated but a have no idea how to calculate the
> median. Is there someone that ever had that problem before? If yes, is
> there a way?
>
> Thanks in advance.
>
> Sylvain. (grenie02_at_cnmtl2.cn.ca)
Received on Sat Feb 22 1997 - 00:00:00 CST

Original text of this message

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