SQL 递归详解数据库

向上   
WITH RECURSIVE r AS (   
SELECT * FROM acu_customercircle    
WHERE circleunitid = 'd05c24fa-dc32-4357-8a48-0f72efdfd85a'  union ALL SELECT    
   
acu_customercircle.* FROM acu_customercircle,   
r WHERE acu_customercircle.circleunitid = r.guidparentid)   
SELECT * FROM r ORDER BY circleunitid;   
   
向下   
WITH RECURSIVE T (circleunitid, strname, guidparentid, dwgrade)  AS (   
    SELECT circleunitid, strname, guidparentid, dwgrade   
    FROM acu_customercircle   
    WHERE circleunitid = '712a9d32-e7d9-41d7-b07f-42a2e8c4a827'   
    UNION ALL   
    SELECT  D.circleunitid, D.strname, D.guidparentid, D.dwgrade   
    FROM acu_customercircle D   
    JOIN T ON D.guidparentid = T.circleunitid)   
    SELECT circleunitid, strname, guidparentid, dwgrade FROM T   
ORDER BY dwgrade;  

  

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/6713.html

(0)
上一篇 2021年7月17日
下一篇 2021年7月17日

相关推荐

发表回复

登录后才能评论