我正在开发一个多级营销项目(MLM),其中节点以树模式添加。
请任何人都可以知道如何编写存储过程来计算每周佣金(mlm树中的收入)下面是我的表结构和数据。
CREATE TABLE Associate_Income
(
ID varchar(30) NOT NULL,
ParentID varchar(30) NULL,
IsLeft tinyint NULL,
IsRight tinyint NULL,
joingdate datetime NOT NULL
)
INSERT Associate_Income
(ID, ParentID, IsLeft, IsRight, joingdate)
SELECT 'Ramesh123', NULL, NULL, NULL '2014-01-03 16:31:15.000' UNION ALL
SELECT 'Sonu', 'Ramesh123', 1, NULL, '2014-01-03 16:45:21.000' UNION ALL
SELECT 'Pawan kumar', 'Ramesh123', NULL, 1, '2014-01-04 16:50:23.000' UNION ALL
SELECT 'Ravi123', 'Sonu', 1, NULL, '2014-01-04 17:03:22.000' UNION ALL
SELECT 'Vineet123', 'Sonu', NULL, 1, '2014-01-04 17:26:01.000' UNION ALL
SELECT 'dev123', 'Ravi123', 1, NULL, '2014-01-05 19:35:16.000' UNION ALL
SELECT 'Mukesh123', 'Ravi123', NULL, 1, '2014-01-05 19:40:41.000' UNION ALL
SELECT 'poonam123', 'Vineet123', 1, NULL, '2014-01-05 19:49:49.000' UNION ALL
SELECT 'monu', 'Pawan kumar', 1, NULL, '2014-01-05 17:32:58.000' UNION ALL
SELECT 'Arti123', 'Pawan kumar', NULL, 1, '2014-01-05 19:54:35.000' UNION ALL
我的数据库表Associate_Income结构如下:
ID ParentID IsLeft IsRight joingdate
Ramesh123 NULL NULL NULL 2014-01-03 16:31:15.000
Sonu Ramesh123 1 NULL 2014-01-03 16:45:21.000
Pawan kumar Ramesh123 NULL 1 2014-01-04 16:50:23.000
Ravi123 Sonu 1 NULL 2014-01-04 17:03:22.000
Vineet123 Sonu NULL 1 2014-01-04 17:26:01.000
dev123 Ravi123 1 NULL 2014-01-05 19:35:16.000
Mukesh123 Ravi123 NULL 1 2014-01-05 19:40:41.000
poonam123 Vineet123 1 NULL 2014-01-05 19:49:49.000
monu Pawan kumar 1 NULL 2014-01-05 17:32:58.000
Arti123 Pawan kumar NULL 1 2014-01-05 19:54:35.000