Re: SELECT statement not working as intended

From: Henry Drexler <alonup8tb(at)gmail(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT statement not working as intended
Date: 2011-10-10 22:25:46
Message-ID: CAAtgU9Sny+3qjXBm2M33DfAufLNvghjcTUah7iYz2p=zkctcGQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

for instance

CalifCrk | CalCrk | 1996-10-18 | 188
CalifCrk | CalCrk | 1996-08-23 | 183
CalifCrk | CalCrk | 1996-07-29 | 201
CalifCrk | CalCrk | 1996-09-27 | 185

188 is the biggest number for 1996-10-18 calcrk califcrk, and so on down the
line.

You need to eliminate the date column in the query, or whatever fits your
requirements.

On Mon, Oct 10, 2011 at 6:24 PM, Henry Drexler <alonup8tb(at)gmail(dot)com> wrote:

> you are also grouping by sample date, those are the largest values for the
> criteria you have set out in the group by.
>
>
>
> On Mon, Oct 10, 2011 at 6:17 PM, Rich Shepard <rshepard(at)appl-ecosys(dot)com>wrote:
>
>> I'm trying to query the table to extract the single highest value of a
>> chemical by location and date. This statement gives me all the values per
>> stream, site, and date:
>>
>> SELECT str_name, site_id, sample_date, max(quant) FROM chemistry WHERE
>> hydro
>> = 'Humboldt' group by str_name, sample_date, site_id order by str_name,
>> site_id;
>>
>> I'm not seeing why this doesn't work; the top few lines of output are:
>>
>> CalifCrk | CalCrk | 1996-10-18 | 188
>> CalifCrk | CalCrk | 1996-08-23 | 183
>> CalifCrk | CalCrk | 1996-07-29 | 201
>> CalifCrk | CalCrk | 1996-09-27 | 185
>>
>> when what I want is only the third line.
>>
>> A clue to the correct syntax is solicited. I'm sure it's something simple
>> that I'm just not seeing.
>>
>> Rich
>>
>> --
>> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/**mailpref/pgsql-general<http://www.postgresql.org/mailpref/pgsql-general>
>>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2011-10-10 22:43:51 Re: SELECT statement not working as intended
Previous Message Henry Drexler 2011-10-10 22:24:28 Re: SELECT statement not working as intended