Single Table Select With Aggregate Function - Mailing list pgsql-general

From Rich Shepard
Subject Single Table Select With Aggregate Function
Date
Msg-id alpine.LNX.2.00.1201031518070.18032@salmo.appl-ecosys.com
Whole thread Raw
Responses Re: Single Table Select With Aggregate Function  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Single Table Select With Aggregate Function  (Ondrej Ivanič <ondrej.ivanic@gmail.com>)
Re: Single Table Select With Aggregate Function  ("David Johnston" <polobo@yahoo.com>)
List pgsql-general
   I'm probably not seeing the obvious so I keep making the same mistake. The
table holds water chemistry data from multiple streams, sites within each
stream, sampling dates, and many chemical constituents.

   What I need to do are three things:

   1.) Find the date and site for the maximum value of a specified constituent
on a named stream.

   2.) Find the values of that same constituent at other sites on the named
stream on that same date.

   3.) Find the date of the maximum value of a constituent for all sites on
the named stream.

   Thinking the last the easiest to do, I submitted this query:

select max(quant), site, sampdate from chemistry where stream = 'SheepCrk'
and param = 'TDS' group by site, sampdate;

but this gives me the value of each site and date, not the maximum for all
dates at a specific site. Postgres tells me that both site and sampdate must
be in the 'group by' clause.

   Obviously the syntax is more complex than I thought it would be and I
would like a pointer to the correct way to write these queries.

Rich



pgsql-general by date:

Previous
From: Roberto Sanchez
Date:
Subject: Re: stop server
Next
From: Tom Lane
Date:
Subject: Re: Single Table Select With Aggregate Function