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

Home -> Community -> Usenet -> c.d.o.tools -> Re: computing median

Re: computing median

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Fri, 20 Apr 2001 21:10:25 +0100
Message-ID: <987798731.22034.0.nnrp-12.9e984b29@news.demon.co.uk>

I think you could do this with the analytic NTILE() function. Take the NTILE(2) of the data, and the median ought to be the average of the max() of the 1st ntile and the min() of the second ntile.

--
Jonathan Lewis
Yet another Oracle-related web site:  http://www.jlcomp.demon.co.uk

Practical Oracle 8i:  Building Efficient Databases
Publishers:  Addison-Wesley

Reviews at: http://www.jlcomp.demon.co.uk/book_rev.html



Scott Watson wrote in message ...

>I don't believe there is a function that does that you need. The only
>solution is to write one yourself in PL?SQL.
>
>eg exec :median := my_stats.median(tablename, column_name);
>
>inside the function you would have to calculate the number of rows in the
>column and then if it is odd take the middle value or else use the two
>values around the center and add them together and divide by 2.
>
>Scott.
Received on Fri Apr 20 2001 - 15:10:25 CDT

Original text of this message

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