Re: How to generate the order if you know the next item for each item?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: How to generate the order if you know the next item for each item?
Дата
Msg-id CAKFQuwb0fdfZRhWDX0qBMB7_4M6T6_2mF2pZ105i=V2qLfDRSg@mail.gmail.com
обсуждение исходный текст
Ответ на How to generate the order if you know the next item for each item?  (Rockdale Green <rockdale.green@gmail.com>)
Ответы Re: How to generate the order if you know the next item for each item?  (Tony Shelver <tshelver@gmail.com>)
Re: How to generate the order if you know the next item for each item?  (Rockdale Green <rockdale.green@gmail.com>)
Список pgsql-sql
On Tue, Aug 3, 2021 at 8:40 AM Rockdale Green <rockdale.green@gmail.com> wrote:
 can I do it in one query? 

Yes.
It might be just very simple and I have tried but somehow I am blocked. 


The feature you need is a recursive CTE (WITH RECURSIVE clause).  It requires an initial row (which in this case is task 3, the only task that doesn't appear as a task_order value) and a query to retrieve the next row(s) using the information available in the previous iteration.

The documentation and/or online resources can walk you through the specifics.

David J.

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

Предыдущее
От: Rockdale Green
Дата:
Сообщение: How to generate the order if you know the next item for each item?
Следующее
От: "Tchouante, Merlin"
Дата:
Сообщение: Like Command returning wrong result set