pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Salvador Mainé <salvamaine@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: I need an aggregate with 2 parameters
Date: Thu, 08 Mar 2001 08:31:19 -0100
Message-ID: <3AA75167.68073235@yahoo.com> (raw)

Hello:

I have a table with pluviometrical data

meteo (rain float, day date, oid station)

I want to select the the day of maximum value for each year for a given
measurement station. It should look like :

select max(rain),day from meteo group by date_part('year', day) where
station=7654765;

though it  obiously doesn't work.

I think that an aggregate function would be the best way to do this,
because the table is quite large and I need indexes for date and also
for stations, so adding a new one for the rain is too much. But the
aggregate should look like:

max_rain(rain, day) and return the day corresponding to the maximum
rain, So the query would be something like:

select max(rain), max_rain(rain, day) from meteo group by
date_part('year', day) where station=47654765;

I've tried to define a composite type for rain and day and the neccesary
functions to make the aggregate, but I cannot find the correct way. Can
someone help me? Is this sollution possible? 

-- 
Salvador Maine
http://www.ronincoders.com



view thread (3+ messages)  latest in thread

Message-ID: <3AA75167.68073235@yahoo.com>
Permalink:  ../3AA75167.68073235@yahoo.com/
Also on:    postgresql.org/message-id/3AA75167.68073235@yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: salvamaine@yahoo.com
  Subject: Re: I need an aggregate with 2 parameters
  In-Reply-To: <3AA75167.68073235@yahoo.com>
  References: <3AA75167.68073235@yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox