I did a procedure for median some time back.
Here is the algorithm that I used.

1. Define a Cursor - Dont forget to use the Order by Column while defining. 
Ofcourse, U should order by the column on which you need median.
2. Get a count of records that cursor would return ( Regarding How to get a 
count - U have to define a similar cursor with the same where clause but 
one that returns count ). Or, simply do a select count into variable.
3. Supposing N is the number of records that the cursor would return,
4. If N is Odd,  Then (N/2)+1 th record is the the median record
5. If N  is even, then the average of the (N/2) th record and (N/2)+1 the 
record is the median value of the set.
6. Now Loop thru the cursor until you encounter (N/2)+1 th record and then 
calculate the median as determined in the steps 4 and 5.


May be I goofed up somewhere - But I am sure my code worked - I checked it 
against a statistical package ( Cornerstone) generated median.

Correct me if I am wrong.
Rajaram.



-----Original Message-----
From:   Tim Sawmiller [SMTP:[EMAIL PROTECTED]]
Sent:   Tuesday, May 15, 2001 3:27 PM
To:     Multiple recipients of list ORACLE-L
Subject:        RE: Mean/Median

Well, no, it doesn't work at all.  The definition of Median is a value 
where half your list of values is above, and half is below.  If the values 
all tend toward the mininum or the maximum, this "equation" would be way 
out of line.

>>> [EMAIL PROTECTED] 05/15/01 01:35PM >>>
Oops, this only works for *even* numbers of samples....geez....

|| -----Original Message-----
|| From: Mohan, Ross
|| Sent: Tuesday, May 15, 2001 12:28 PM
|| To: '[EMAIL PROTECTED]'
|| Subject: RE: Mean/Median
||
||
|| geez louise,
||
|| Median := avg(Max,Min)
||
|| || -----Original Message-----
|| || From: Pat Hildebrand [mailto:[EMAIL PROTECTED]]
|| || Sent: Monday, May 14, 2001 10:56 PM
|| || To: Multiple recipients of list ORACLE-L
|| || Subject: Re: Mean/Median
|| ||
|| ||
|| ||
|| || >
|| || > Any scripts (sql or pl/sql) out there to compute various
|| || statistical things
|| || > in Oracle?
|| || >
|| ||
|| || Would depend on just what you are looking for. A quick look at
|| || Oracle's SQL functions showed avg, st. deviation, and variance
|| || although no median but that should be easier to write than
|| || some of the
|| || others.
|| ||
|| ||                    Pat
|| || --
|| || Please see the official ORACLE-L FAQ: http://www.orafaq.com
|| || --
|| || Author: Pat Hildebrand
|| ||   INET: [EMAIL PROTECTED]
|| ||
|| || Fat City Network Services    -- (858) 538-5051  FAX:
|| (858) 538-5051
|| || San Diego, California        -- Public Internet access /
|| || Mailing Lists
|| ||
|| --------------------------------------------------------------------
|| || To REMOVE yourself from this mailing list, send an E-Mail message
|| || to: [EMAIL PROTECTED] (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).
|| ||
||
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Mohan, Ross
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (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).

--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Tim Sawmiller
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (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).

NetZero Platinum
No Banner Ads and Unlimited Access
Sign Up Today - Only $9.95 per month!
http://www.netzero.net
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Rajaram
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (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).

Reply via email to