mardi 14 juillet 2015

traversing a tree in two different columns in sqlite using python

My sqlite database has two columns named child and parent , any element with value 0 will be root of the tree , Sample data:

child  parent
33     16
16     0
45     39
30     0

I am trying to write a sqlite query to determine number of trees & its path as shown below number of trees : 2

0 16 33
0 30 49

I am able to find out the rows with 0s ...but not able to think of a logic to generate the path..

Any suggestions please

Aucun commentaire:

Enregistrer un commentaire