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

问题描述 投票:0回答:1

有没有办法通过其父代ID来获得左右子代总数,直到子级别的“ N”个。

binary tree

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

user table

位置:

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

欢迎任何帮助或任何建议。

php mysql laravel binary-tree
1个回答
0
投票

嵌套的集合模型更有意义吗?

            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
© www.soinside.com 2019 - 2024. All rights reserved.