sql 查询所有子节点示例

每天学习一点点 编程PDF电子书、视频教程免费下载:
http://www.shitanlife.com/code

 

 

    <!-- 查询机构的所有子机构 -->
    <select id="queryOrgEduAndChildrenForList" parameterType="java.util.Map"
        resultType="com.tianwen.springcloud.microservice.user.entity.OrgEdu">
            WITH RECURSIVE cte AS (
                SELECT
                    edu.*
                FROM
                    t_e_org_edu edu 
                where edu.orgId = #{orgId}
                AND edu.status = '1'
                UNION ALL
                    SELECT
                        b.*
                    FROM
                        t_e_org_edu b
                    INNER JOIN cte C ON b.parentorgid = C .orgid
                    WHERE
                        b.status = '1'
            ) SELECT
                *
            FROM
                cte
            WHERE
                 1 = 1
            <if test="orgType != null">
                and orgtype = #{orgType}
            </if>
    </select>

 

posted @ 2018-05-22 14:51  漫步CODE人生  阅读(752)  评论(0编辑  收藏  举报