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 compute median ?

Re: how to compute median ?

From: Jusung Yang <JusungYang_at_yahoo.com>
Date: 10 Oct 2002 10:23:39 -0700
Message-ID: <130ba93a.0210100923.6e3c53dc@posting.google.com>


Well, nothing is wrong with the way I calculated the median, yes? Though PERCENTILE_DISC(0.5) is a more direct approach in evaluating the median. So instead of using the row_number and ceil like

select c1 from (select c1, row_number() over (order by c1) rn, ceil(count(1) over()/2) mdn from
t2) where rn=mdn;

the SQL would become like

select c1 from (select c1, percentile_disc(0.5) within group (order by c1) over() prn from t2)
where c1=prn;

But yes, percentile_disc(0.5) is more straight forward in getting the median and is a bit easier to understand.

"Finn Ellebaek Nielsen" <fen_at_changegroup.dk> wrote in message news:<3da540b8$0$79635$edfadb0f_at_dspool01.news.tele.dk>...
> This is incorrect. With the SQL analytic functions this is possible through
> PERCENTILE_DISC(0.5).
>
> HTH.
>
> Finn
Received on Thu Oct 10 2002 - 12:23:39 CDT

Original text of this message

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