Re: sql group by statement

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: sql group by statement
Дата
Msg-id 26755.1032015809@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: sql group by statement  ("Albrecht Berger" <berger1517@gmx.ch>)
Список pgsql-sql
"Albrecht Berger" <berger1517@gmx.ch> writes:
> but how do I know that "distinct on" doesn't cut off
> the row with max(val2) of that id that I need ?

Because you do
SELECT DISTINCT ON (id) ... ORDER BY id, val2 DESC;

The DISTINCT keeps the first of each group of rows with the same id,
and by virtue of the ORDER BY (which acts first) the max val2 will be
the first row in that group.  Note there's no GROUP BY in this approach.
        regards, tom lane


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

Предыдущее
От: Christopher Kings-Lynne
Дата:
Сообщение: Re: Table alias in DELETE statements
Следующее
От: "Florian Mader"
Дата:
Сообщение: Re: Timestamp Fractions Problem