Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: sql/function to calculate the median
(Since I've not seen any responses to this I'll give it a go.)
If you can use OLAP functions, have a look at PERCENTILE_CONT--that gives you any percentile you need--median is of course 50th.
There is a nice discussion of this & several candidate solutions in Celko's _SQL For Smarties_.
I was thinking you might be able to do something quick-n-dirty by counting the number of non-null values in the column whose median you need & then selecting out the value that falls at rownum = round(count/2,0) in a properly ordered result set. But I couldn't get that to work on a test table, so I won't post my code.
HTH,
-Roy
Roy Pardee
Programmer/Analyst
SWFPAC Lockheed Martin IT
Extension 8487
-----Original Message-----
Sent: Monday, April 21, 2003 12:12 PM
To: Multiple recipients of list ORACLE-L
Hi All,
Oracle 8.0.5
Does anyone have sql statement/functin to calculate the median?
Thanks
Rick
--
Please see the official ORACLE-L FAQ: http://www.orafaq.net
--
Author:
INET: Rick_Cale_at_teamhealth.com
Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting servicesto: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting servicesto: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Tue Apr 22 2003 - 14:31:53 CDT
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
![]() |
![]() |