美文网首页
递归函数取子集

递归函数取子集

作者: M_ENG | 来源:发表于2020-11-26 11:39 被阅读0次
    CREATE DEFINER=`root`@`%` FUNCTION `GET_CHILD_COMMENT_STR`(id VARCHAR(50)) RETURNS longtext CHARSET utf8mb4
        SQL SECURITY INVOKER
    BEGIN
      DECLARE r LONGTEXT default ''; 
        set r = (SELECT GROUP_CONCAT(PICK_COMMENT_ID) FROM (
    
            SELECT T1.PICK_COMMENT_ID,
    
            IF(FIND_IN_SET(REPLY_PICK_COMMENT_ID, @PIDS) > 0, @PIDS := CONCAT(@PIDS, ',', PICK_COMMENT_ID), 0) AS ISCHILD
    
            FROM (
    
            SELECT PICK_COMMENT_ID,REPLY_PICK_COMMENT_ID FROM APP_PICK_COMMENT T WHERE T.STATUS = '0' ORDER BY T.REPLY_PICK_COMMENT_ID, T.PICK_COMMENT_ID
    
            ) T1,
    
            (SELECT @PIDS := id) T2
    
            ) T3 WHERE ISCHILD != 0);
    RETURN r;
    END
    

    相关文章

      网友评论

          本文标题:递归函数取子集

          本文链接:https://www.haomeiwen.com/subject/iouaiktx.html