sql递归查出某个值下的所有子集数据
一、mapper层
List<Long> selectListById(@Param "grpId") String grpId);
二、xml层
<select id="selectListById" resultType="java.lang.Long">
WITH RECURSIVE subordinates AS (
SELECT id,str01,tenant_id
FROM cloud_base_person
WHERE str01 = #{grpId}
UNION ALL
SELECT t.id, t.str01, t.tenant_id
FROM cloud_base_persont
INNER JOIN subordinates s ON t.str01 = s.id
WHERE t.deleted != '1' AND t.tenant_id = s.tenant_id
)
SELECT id FROM subordinates;
</select>