Search Postgresql Archives

Single Table Select With Aggregate Function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  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



--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux