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

Поиск
Список
Период
Сортировка
От Rockdale Green
Тема How to generate the order if you know the next item for each item?
Дата
Msg-id CAArxxWj=_gc=6RL0QGPzpbXMLZTvxDOqG-sQVxbpCmVu5Q2jpQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: How to generate the order if you know the next item for each item?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-sql
Hi, all:

I have two tables one is a lookup for all the tasks, another table stores the next task for each task, I want to generate a list of tasks with its sequence number, can I do it in one query? 

Table task

id  name 
1   postoffice
2   grocery store
3.  walk dog
4.  swimming 
5   roller skate
7   biking


table next_task

task   next_task
3         7
7         1
1          4
4          2
2          5

and I want to get the list in order 

task                task_order 
3 (walk dog)              1
7 (biking)                   2
1 (postoffice)             3  
4 (swimming)             4
2 (growcery store)      5
5 (roller skate)            6

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

Thanks in advance
-Rockdale 


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

Предыдущее
От: Steve Midgley
Дата:
Сообщение: Re: Equivalent of InternalRowsAffected in NonExecuteQuery for PostgreSQL
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: How to generate the order if you know the next item for each item?