Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: how to compute median ?
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