Re: MEDIAN as custom aggregate?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Josh Berkus" <josh(at)agliodbs(dot)com>
Cc: Allan Engelhardt <allane(at)cybaea(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: MEDIAN as custom aggregate?
Date: 2001-10-13 05:31:54
Message-ID: 8803.1002951114@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Josh Berkus" <josh(at)agliodbs(dot)com> writes:
> The query I'll use is this:

> SELECT site, COUNT(pageviews) as count_views, AVG(pageviews) AS
> mean_views, median_views
> FROM sites,
> (SELECT pageviews as median_view
> FROM pageviews
> LIMIT 1 OFFSET middlerec('pageviews')) med
> GROUP BY site, median_views;

> Where middlerec is a custom function that counts the records and returns
> the middle one.

Um ... does that work? I thought LIMIT was fairly restrictive about
what it would take as a parameter --- like, constants or $n parameters
only.

I do not know of any median-finding algorithm that doesn't require a
depressingly large amount of storage...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Pat M 2001-10-13 12:55:14 Cenceptual help needed - periodic events
Previous Message Stephan Szabo 2001-10-13 05:26:20 Re: GROUPING