Re: SELECT statement not working as intended

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: SELECT statement not working as intended
Дата
Msg-id CAHyXU0z7WMmoxDCB-DiO7uzN4+HRFp0+Ltzx2a6xBa_P4H3KXQ@mail.gmail.com
обсуждение исходный текст
Ответ на SELECT statement not working as intended  (Rich Shepard <rshepard@appl-ecosys.com>)
Ответы Re: SELECT statement not working as intended
Список pgsql-general
On Mon, Oct 10, 2011 at 5:17 PM, Rich Shepard <rshepard@appl-ecosys.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.

remove the sample_date the group by and the select list.  by having it
in there you are asking for the max for each specific sample date.

merlin

В списке pgsql-general по дате отправления:

Предыдущее
От: Rich Shepard
Дата:
Сообщение: SELECT statement not working as intended
Следующее
От: Henry Drexler
Дата:
Сообщение: Re: SELECT statement not working as intended