Re: How to select rows that are the max for each subcategory?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to select rows that are the max for each subcategory?
Дата
Msg-id 9717.1222366355@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How to select rows that are the max for each subcategory?  ("Kynn Jones" <kynnjo@gmail.com>)
Ответы Re: How to select rows that are the max for each subcategory?  ("Kynn Jones" <kynnjo@gmail.com>)
Список pgsql-general
"Kynn Jones" <kynnjo@gmail.com> writes:
> Suppose I have a table T that has, among its columns, the fields X and Y,
> where Y is an integer, and multiple rows with the same value of X are
> possible.  I want to select the rows corresponding to the greatest values of
> Y for each value of X.

You could use DISTINCT ON --- see the "weather reports" example in the
SELECT reference page.  It's not standard SQL but will usually be faster
than solutions that use only standard features.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Indirect access to NEW or OLD records
Следующее
От: Casey Allen Shobe
Дата:
Сообщение: Re: Oracle and Postgresql