子节点在Mysql中使用分层查询

时间:2016-05-30 14:21:05

标签: mysql

我试图找出Mysql DB中的所有子节点。我在网上搜索同样的解决方案,但它对我不起作用。我在oracle中使用connnect做了这个,但是我需要在mysql中使用它。请帮我。 这是我的故事的数据 MySQL的> select * from membertable;

+----------+------------+----------+-------+
| memberid | membername | parentId | leg   |
+----------+------------+----------+-------+
|      101 | abc        |     NULL | NULL  |
|      102 | def        |      101 | Left  |
|      103 | jkl        |      101 | Right |
|      104 | ghi        |      102 | Left  |
|      105 | mno        |      102 | Right |
|      106 | pqr        |      103 | Left  |
|      107 | stu        |      103 | Right |
+----------+------------+----------+-------+

假设我传递了memberid = 102,我期待这样的数据。

+----------+------------+----------+-------+
|      102 | def        |      101 | Left  |
|      104 | ghi        |      102 | Left  |
|      105 | mno        |      102 | Right |
|      106 | pqr        |      103 | Left  |
|      107 | stu        |      103 | Right | 
+----------+------------+----------+-------+

请做得好......

0 个答案:

没有答案
相关问题