Single Table Select With Aggregate Function

Поиск
Список
Период
Сортировка
От Rich Shepard
Тема Single Table Select With Aggregate Function
Дата
Msg-id alpine.LNX.2.00.1201031518070.18032@salmo.appl-ecosys.com
обсуждение исходный текст
Ответы 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>)
Список 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 по дате отправления:

Предыдущее
От: Roberto Sanchez
Дата:
Сообщение: Re: stop server
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Single Table Select With Aggregate Function