| От | Tom Lane |
|---|---|
| Тема | Re: Re: Restriction by grouping problem. |
| Дата | |
| Msg-id | 2229.996436952@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: Re: Restriction by grouping problem. (Philip Warner <pjw@rhyme.com.au>) |
| Список | pgsql-sql |
Philip Warner <pjw@rhyme.com.au> writes:
> This will work, but will not solve the larger problem of 'give me all the
> attrs of of the record with the least datetime for a given SID'. Jeff does
> not need this, but it is a common problem. Simply using min/max works for
> one attr, but fails to provide a consistent view of multiple attrs. PG has
> no elegant single-statement solution to this problem.
Yes it does:
SELECT DISTINCT ON (sid) * FROM logs ORDER BY sid, datetime;
This gives you just one output row per distinct "sid" value, and that
row will be the one with least datetime.
See the DISTINCT ON example in the SELECT reference page.
regards, tom lane
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера