多层次行销 [英] Multilevel marketing
问题描述
我正在开发一个包含二叉树的多级营销站点.
我能够生成树,但是我的问题是基于总左连接和总右连接进行计算.
您能建议任何方法或查询来计算吗?
我的表格结构是
User_id Left_id Right_id
1 2 3
2 4 5
3 6 7
4 8 9
5 10 11
6 12 13
7 14 15
这意味着对于user_id 1,leftcount = 8 rightcount = 7
结构如下:
1
2 3
4 5 6 7
8 9 10 11 12 13 14 15
Hi,
I am developing a multilevel marketing site which contains a binary tree.
I am able to generate the tree but my problem is calculating on total left join and total right join.
Can you suggest any method or query to calculate this.
My Table structure for this is
User_id Left_id Right_id
1 2 3
2 4 5
3 6 7
4 8 9
5 10 11
6 12 13
7 14 15
That means for user_id 1 leftcount=8 rightcount=7
structure is like below:
1
2 3
4 5 6 7
8 9 10 11 12 13 14 15
If anyone finds it do reply.
推荐答案
如果您想要特定元素的腿数,则只有递归
这只是关于功能的一个想法
函数GetLeftCount(User_ID)AS整数
LeftID = FindLeftID(User_ID)''''''''获取左侧ID
如果不是LeftID则什么都不是
返回GetLeftCount(Left_ID)+1''''再次调用同一函数
其他
返回1
结束
请注意,这不是任何一种特定于语言的代码
If you want the legs count of a particular element Recursion is the only way
Here is just an idea about the function
Function GetLeftCount(User_ID) AS integer
LeftID = FindLeftID(User_ID) '''''''' Fetch the left ID
if not LeftID is nothing
Return GetLeftCount(Left_ID) + 1 '''' Call the same function again
else
Return 1
End
Note that this is not any kind of Language Specific Code
这篇关于多层次行销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!