如圖:
表資料這樣的一棵樹,如何獲取「高寅瑞」下的所有節點(一條sql語句是肯定搞不定的)
通過儲存過程來寫
delim //
create function `ge程式設計客棧tchildlst`(rootid int)
returns varchar(10syqeeosqw00) reads sql data
begin
declare stemp varchar(1000);
declare stempchd varchar(1000);
set stemp = '$';
set stempchd =cast(rootid as char);
while stempchd is not null do
程式設計客棧
set stemp = concat(stemp,',',stempchd);
select group_concat(id) into stempchd from document_file_name where find_in_set(pid,stempchd)>0;
end while;
return stemp;
end //
建立如上儲存過程
se程式設計客棧lect * from document_file_name where find_in_set(id, getchildlst(1));
總結
MySQL 使用儲存過程實現留存率
delimiter use resourcemanage dev drop procedure if exists stat remain player create definer root localhost procedure stat remain player begin 今天的日期 de...
mysql儲存登入 MYSQL儲存過程實現使用者登入
create definer root function uc session login re son json,srvjson json returnsjson language sqlnotdeterministiccontainssql sql security definer commen...
Mysql儲存過程使用
案例 create procedure sp insert graduate certificate in psid varchar 200 in certificateid int 32 in number varchar 50 in userid int 32 in starttime date...