Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Calculating of the Median of Data
> Does anyone have a handy function for calculating the Median of data ??
It
> seems like it should be simple ...but
Kevin,
Maybe not as simple as you think. :)
Here's an example in SQL. You may want to dig through the archives, as this was discussed at some lenght a few months ago.
Ross may remember it.
Jared
drop table median;
create table median ( value number );
insert into median values ( 111 ); insert into median values ( 543 ); insert into median values ( 566 ); insert into median values ( 643 ); insert into median values ( 456 ); insert into median values ( 98 ); insert into median values ( 877 ); insert into median values ( 867 ); insert into median values ( 687 ); insert into median values ( 6886 );
commit;
break on report
compute avg label 'Median' of value on report
column value heading 'values|averaged|in median'
select
rownum, value from ( select value from median where value is not null union select 1 from dual where 1=2
select decode( mod(total_freq,2), 1,trunc(total_freq/2 + 1), 0,trunc(total_freq/2) ) from ( select count(*) total_freq from median where value is not null )
select decode( mod(total_freq,2), 1,trunc(total_freq/2 + 1), 0,trunc(total_freq/2 + 1) ) from ( select count(*) total_freq from median where value is not null )
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author:
INET: Jared.Still_at_radisys.com
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Liststo: 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 Fri Jun 22 2001 - 11:24:19 CDT
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message