Re: Subquery to select max(date) value

Поиск
Список
Период
Сортировка
От Jan Kohnert
Тема Re: Subquery to select max(date) value
Дата
Msg-id 36049066.FvorQsyXWJ@kohnert-n4
обсуждение исходный текст
Ответ на Subquery to select max(date) value  (Rich Shepard <rshepard@appl-ecosys.com>)
Список pgsql-general
Am Dienstag, 12. Februar 2019, 23:23:49 CET schrieb Rich Shepard:
> The query is to return the latest next_contact date for each person. Using
> the max() aggregate function and modeling the example of lo_temp on page 13
> of the rel. 10 manual I wrote this statement:

You don't even need a subselect to do so:

select 
    P.person_id, P.lname, P.fname, P.direct_phone, 
    O.org_name, max(A.next_contact) as next_contact
from People as P
join Organizations as O
    on P.org_id = O.org_id
join Activities as A
    on P.person_id = A.person_id
group by 
    P.person_id, P.lname, P.fname, 
    P.direct_phone, O.org_name;

-- 
Kind regards Jan





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

Предыдущее
От: Daniel Westermann
Дата:
Сообщение: Is the ring buffer not used for index blocks
Следующее
От: PegoraroF10
Дата:
Сообщение: Re: Server goes to Recovery Mode when run a SQL