Re: query, probably needs window functions

Поиск
Список
Период
Сортировка
От Michael Lewis
Тема Re: query, probably needs window functions
Дата
Msg-id CAHOFxGpwuPCSmuSiD9yKDG_rTbvmU156LX3ckRdEo5ixy-NM9g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: query, probably needs window functions  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: query, probably needs window functions
Re: query, probably needs window functions
Список pgsql-general
I believe something like this is what you want. You might be able to do it without a sub-query by comparing the current name value to the lag value and null it out if it's the same.

select
case when row_number = 1 then id end AS id, 
case when row_number = 1 then name end as name,
phone.number
from(
select person.id, person.name, phone.number, row_number() partition by( phone.person_id order by phone.number ) as row_number
from person
join phone on person.id = phone.person_id
) AS sub
order by name, row_number;

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

Предыдущее
От: "Andrus"
Дата:
Сообщение: Re: Query returns no rows in pg_basebackup cluster
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: query, probably needs window functions