SET stemp= ' $ ';
SET stempchd = CAST (Id as CHAR); --Conversion data format
While Stempchd was not NULL do--start loop
SET stemp= CONCAT (stemp, ', ', stempchd); --string concatenation
SELECT Group_concat (ID) into Stempchd from ' user ' WHERE find_in_set (pid,stempchd) >0;
--Group_concat () calculates which rows belong to the same group and divides the same set of parameters into strings separated by commas;
--Find_in_set (PID,STEMPCHD) to determine whether the PID is in Stempchd
--the statement means querying the user table, the PID of the data being queried is in Stempchd, and the ID found is a comma-separated string, re-assigned to Stempchd; when Stempchd has a value, loops again, no value, jumps out of the loop,
--the data in the loop is spelled into a stemp string
END while;
--handling of Stemp
SELECT LENGTH (stemp)-length (replace (stemp, ', ', ')) into Invitorn;
SET Invitorn = Invitorn + 1;
While J <= Invitorn do
SELECT Substring_index (stemp, ', ', J) into TempStr;
SELECT SUBSTRING (tempstr,m+1) into Tempuserid;
SET M = LENGTH (tempstr) + 1;
SET j = J +1;
IF Tempuserid! = UserId Then
Xxxx
END IF;
END while;
MySQL recursive query