Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: computing median
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 ...Received on Fri Apr 20 2001 - 15:10:25 CDT
>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.
![]() |
![]() |