A
A
Alexey Shashenkov2018-06-19 16:11:52
SQL
Alexey Shashenkov, 2018-06-19 16:11:52

How to get data in the form of a graph from a database (sql)?

There is data. Where value is the target data, and prew and next are the data in what order they are.

| value | prew | next |
| 1     | 5    | 6    |
| 2     | 4    | 3    |
| 3     | 2    | 5    |
| 4     | 0    | 2    |
| 5     | 3    | 1    |
| 6     | 1    | null |

It is required to get value from the database in the sequence as described in prew, next.
| value | prew | next |
| 4     | 0    | 2    |
| 2     | 4    | 3    |
| 3     | 2    | 5    |
| 5     | 3    | 1    |
| 1     | 5    | 6    |
| 6     | 1    | null |

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan., 2018-06-19
@LaRN

Look towards recursive common table expressions:
https://habr.com/post/43955/
https://docs.microsoft.com/ru-ru/sql/t-sql/queries...

P
ponaehal, 2018-06-21
@ponaehal

If Oracle, then google the words SELECT CONNECT BY PRIOR

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question