I would like to generate sequence numbers for select that gives sub numbers for descendant items.
I want the numbers be the following format:
- root: 1...n
- children of root: 1.1 -> 1.n
- sub children: 1.1.1 -> 1.1.n
- and so on...
I have Item table which has an owner_ref foreign key the table: (name of items is just an example, it can be anything)
id | item_name | parent_id | owner_ref_id
----|------------|-----------|--------------
1 | item_1 | null | 1
2 | item_1.1 | 1 | 1
3 | item_1.1.1 | 2 | 1
4 | item_2 | null | 1
5 | item_2.1 | 4 | 1
6 | item_2.2 | 4 | 1
--------------------------------------------
The outcome should looks like :
seq_num | item_name | parent_id | owner_ref_id
---------|------------|-----------|--------------
1 | item_1 | null | 1
1.1 | item_1.1 | 1 | 1
1.1.1 | item_1.1.1 | 2 | 1
2 | item_2 | null | 1
2.1 | item_2.1 | 4 | 1
2.2 | item_2.2 | 4 | 1
--------------------------------------------