Re: Subquery to select max(date) value

Поиск
Список
Период
Сортировка
От Andrew Gierth
Тема Re: Subquery to select max(date) value
Дата
Msg-id 87mulev72k.fsf@news-spur.riddles.org.uk
обсуждение исходный текст
Ответ на Re: Subquery to select max(date) value  (Rich Shepard <rshepard@appl-ecosys.com>)
Ответы Re: Subquery to select max(date) value [RESOLVED]
Список pgsql-general
>>>>> "Rich" == Rich Shepard <rshepard@appl-ecosys.com> writes:

 Rich> Tried this and did not do it correctly. Should there be two
 Rich> 'order by', one in the sub-query, the other in the top-level
 Rich> query?

Yes.

 Rich> This does not return the desired order:

 Rich> select p.person_id, p.lname, p.fname, p.direct_phone, p.active, o.org_name, sq.*
 Rich> from people as p
 Rich>      join organizations as o on p.org_id = o.org_id
 Rich>      cross join
 Rich>          lateral
 Rich>          (select a.next_contact
 Rich>          from activities as a
 Rich>              where a.person_id = p.person_id and
 Rich>              p.active='True' and
 Rich>              a.next_contact is not null
 Rich>          order by a.next_contact DESC
 Rich>          limit 1) sq
 Rich>          order by sq.next_contact DESC;

That query seems correct assuming you want the result in descending
order of next_contact. How did the actual result differ from your
expectation?

-- 
Andrew (irc:RhodiumToad)



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

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Subquery to select max(date) value
Следующее
От: github kran
Дата:
Сообщение: Archival process of partition tables with filtering few rows from tables.