Subject | Re: Calculating median value on a large table |
---|---|
Author | Svein Erling |
Post date | 2004-01-13T09:31:01Z |
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
consuming.
Set
- I support Firebird, I am a FirebirdSQL Foundation member.
- Join today at http://www.firebirdsql.org/ff/foundation
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
consuming.
Set
- I support Firebird, I am a FirebirdSQL Foundation member.
- Join today at http://www.firebirdsql.org/ff/foundation
--- In firebird-support@yahoogroups.com, Bill Katelis wrote:
> Hi,
> Using FirebirdCS-1.5.0.4027-RC7.i686.rpm:
>
> 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