Re: Selecting All Columns Associated With Maximum Value of One Column

Поиск
Список
Период
Сортировка
Искать
От
David Johnston
Тема
Re: Selecting All Columns Associated With Maximum Value of One Column
Дата
Msg-id
89C34F51-D687-48B2-8DC5-3DDAD127EE96@yahoo.com
Ответ на
Список
Дерево обсуждения
Selecting All Columns Associated With Maximum Value of One Column Rich Shepard <rshepard@appl-ecosys.com>
Re: Selecting All Columns Associated With Maximum Value of One Column David Johnston <polobo@yahoo.com>
Re: Selecting All Columns Associated With Maximum Value of One Column Rich Shepard <rshepard@appl-ecosys.com>
Re: Selecting All Columns Associated With Maximum Value of One Column Thomas Kellerer <spam_eater@gmx.net>
Re: Selecting All Columns Associated With Maximum Value of One Column Rich Shepard <rshepard@appl-ecosys.com>
Re: Selecting All Columns Associated With Maximum Value of One Column David Johnston <polobo@yahoo.com>
Re: Selecting All Columns Associated With Maximum Value of One Column Rich Shepard <rshepard@appl-ecosys.com>
Re: Selecting All Columns Associated With Maximum Value of One Column Gavin Flower <GavinFlower@archidevsys.co.nz>
Re: Selecting All Columns Associated With Maximum Value of One Column Chris Curvey <chris@chriscurvey.com>
Re: Selecting All Columns Associated With Maximum Value of One Column Rich Shepard <rshepard@appl-ecosys.com>
On Oct 6, 2011, at 9:34, Rich Shepard  wrote:

> On Wed, 5 Oct 2011, David Johnston wrote:
> 
>> 2) "Window" -  max(quant) OVER (PARTITION BY ...)
> 
>  Hmm-m-m. I have a problem here emulating the example on the document page.
> Regardless of which column is first after SELECT postgres tells me that
> column does not exist.
> 
> select site_id, sample_date, param, max(quant) over (partition by param)
> chemistry;
> ERROR:  column "site_id" does not exist
> LINE 1: select site_id, sample_date, param, max(quant) over (partiti...

Missing the FROM before chemistry

>               ^
> select str_name, site_id, sample_date, param, max(quant) over (partition by
> str_name) chemistry;
> ERROR:  column "str_name" does not exist
> LINE 1: select str_name, site_id, sample_date, param, max(quant) ove...
>               ^
>  What am I doing incorrectly here?
> 
>  Also, with the window function can I limit the output to a single str_name
> and param?

Not directly.  After you create the windowed result you can turn it into a sub-query and filter that.  The other form suggested (where quant = select max(quant) from chemistry where ...) is probably a better performer though for your need - I did't read the subject line closely enough and my two options don't directly give you what you are looking for.  Though era ing the window query and then adding a (where quant_max = quant) clause would get you closer; quant_max being the column alias for the window expression.

> 
> Rich
> 

David J.


В списке pgsql-general по дате отправления
От: Rory Campbell-Lange
Дата:
От: Rich Shepard
Дата:
FAQ