可以先创建函数,然后调用。
drop function if exists queryChildCommentId;delimiter //create function queryChildCommentId(parentId int)returns varchar(4000)begindeclare ret varchar(4000);declare retTmp varchar(4000);set ret = '$';set retTmp = cast(parentId as char);while retTmp is not null doset ret = concat(ret, ',' , retTmp);select group_concat(comment_parent_id) into retTmp from t_comment where find_in_set(parentId, retTmp) > 0;end while;return retTmp;end//delimiter ;select queryChildCommentId(0);
新闻热点
疑难解答