Subject Re: Calculating median value on a large table
Author Svein Erling
Depending upon your database, one option could be to have another
table containing the total number of records per age. This table would
have to be updated through an after insert/update/delete trigger.
Though it could lead to problems if there are lots of concurrent
updating of your database - it is not very uncommon for persons to be
of the same age.

If there are lots of conflicts like this, you could of course try to
rather insert into one 'change table' with your trigger and then run a
procedure updating the total number of records per age according to
this change table (and removing the records from the change table) at
set intervals.

It is of course also possible to simply use a stored procedure to find
the median, but with 30 million records this would be somewhat time

- I support Firebird, I am a FirebirdSQL Foundation member.
- Join today at

--- In, Bill Katelis wrote:
> Hi,
> Using FirebirdCS-
> 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) ?
> thanks
> bill