我建了一個存儲過程,沒有工作。這從一個主管ID開始,找到所有的孩子和他們的孩子。謹防循環關係!
假設: Employee表中有PID(人)和SupID(主管)
Emailtable具有PID,PERSONNAME,電子郵件,Nodelevel(INT),開始是空的。
呼叫Nodeup(1,SupervisorID)(參數CURNODE INT,IN supid INT)
BEGIN
#Routine body goes here...
declare newnode int;
if curnode = 1 then
insert emailtable (pid,personname,email,nodelevel) select pid,personname,email,1 from employees where pid = superid;
end if;
insert emailtable(personname,pid,email,nodelevel) select personname,pid,email,curnode+1
from employees where supid in (select pid from emailtable where curnode = emailtable.nodelevel);
set newnode = (select max(nodelevel) from emailtable);
if newnode > curnode then
call nodeup(Newnode,0);
end if;
END
這是否以爲我的表是鄰接表,我轉換爲嵌套組? – blankip