On Tue, 13 Jan 2004 01:36:57 +0000 (UTC), Bill Katelis wrote:
Suppose I have a table with 30 million records as follows:
create table (
name char(10),
age integer
);
Can anybody suggest an efficient method of calculating the median age (not
average) ?
I would this on the client. Start with select AGE, count(*)
from <whatever table>
group by AGE
This returns just a few records (about 100 ?). Now, find the exact number
of rows (if necessary, read the records (counts) into
an integer table). Then, it should be easy to find the median (if I
haven't forgotten what the 'median' should be ...)