提问者:小点点

在mysql中获取根用户的左右子的计数


是否有任何方法可以通过其父id得到左和右子级的总数,直到子级的“N”个。

这是我的用户表,我在其中存储带有腿(左/右)位置的父子信息

其中:

1. referral_id : is the id of parent user of child user
2. left_child_id : is the id of child user who joined the user on left leg
3. right_child_id : is the id of child user who joined the user on right leg.
4. position_to_referral : is the position name(left/right leg) where he joined the parent user

欢迎任何帮助或任何形式的建议。


共1个答案

匿名用户

嵌套集模型不是更有意义吗?

            1 A 14
              |
      +-------+--------+
      |                |
    2 B 7            8 C 13
      |                |
  +---+---+       +----+----+
  |       |       |         |
3 D 4   5 E 6   9 F 10   11 G 12


user lft rgt
A      1  14
B      2   7
C      8  13
D      3   4
E      5   6
F      9  10
G     11  12