Re: SELECT statement not working as intended

From: Scott Marlowe <scott(dot)marlowe(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-11 00:15:35
Message-ID: CAOR=d=23a0FVoc9nmiUnFJZ6A=kAuJ2x+WVSQgqut=3KJi-OLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Oct 10, 2011 at 6:14 PM, Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> wrote:
> On Mon, Oct 10, 2011 at 4: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.

Correction.

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 order by 4 desc limit 1;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2011-10-11 00:17:17 Re: SELECT statement not working as intended
Previous Message Scott Marlowe 2011-10-11 00:14:09 Re: SELECT statement not working as intended