Quantcast
Channel: Active questions tagged cte - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 207

Order a nested table with path index according to list_order in SQLite

$
0
0

I have a SQL table with this nested structure:

CREATE TABLE items (`id` INTEGER, `item_name` VARCHAR(6), `parent_id` INTEGER, `list_order` INTEGER);

My SQLite version does not support window function, currently my query at link SQLite query are returning as follow the result, but it's not ordered according to list_order, another detail is that the list_order column could come with all values equal to zero.

   id      name_item   parent_id  level  path_index list_order---------------------------------------------------------------   1        Pois           0          0     1           4   2        Então          0          0     2           5   3        Teste          0          0     3           3   11       Teste 3        3          1     3.1         2   12       Teste 2        3          1     3.2         0   13       Teste 1        3          1     3.3         1   4        Fundo          0          0     4           2   7        Profundo       4          1     4.1         1   8        Dhdhd          4          1     4.2         0   9        Gagagaga       8          2     4.2.1       1   10       Fsfsfsfs       8          2     4.2.2       0   5        Profundo       0          0     5           1   6        Gigante        0          0     6           6   14       Teste          0          0     7           0

What I want the path_index column to follow list_order and level columns, like here:

   id      name_item   parent_id  level  path_index list_order---------------------------------------------------------------   14       Teste          0          0     1           0   5        Profundo       0          0     2           1   4        Fundo          0          0     3           2   8        Dhdhd          4          1     3.1         0   10       Fsfsfsfs       8          2     3.1.1       0   9        Gagagaga       8          2     3.1.2       1   7        Profundo       4          1     3.2         1   3        Teste          0          0     4           3   12       Teste 2        3          1     4.1         0   13       Teste 1        3          1     4.2         1   11       Teste 3        3          1     4.3         2   1        Pois           0          0     5           4   2        Então          0          0     6           5   6        Gigante        0          0     7           6

How can I align the path_index sorted according to list_order and level columns?


Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>