三级分销会员一次查询出来的SQL语句
SELECT
p.id AS partyId,
p.parent_id AS parentId,
pul.username AS userName,
p.city,
p.birth_date AS birthDate,
p.phone AS telePhoneNo
FROM
party p
LEFT JOIN party_user_login pul ON pul.party_id = p.id
WHERE 1=1 AND p.parent_id = 57
union all
SELECT
p.id AS partyId,
p.parent_id AS parentId,
pul.username AS userName,
p.city,
p.birth_date AS birthDate,
p.phone AS telePhoneNo
FROM
party p
LEFT JOIN party_user_login pul ON pul.party_id = p.id
WHERE 1=1 AND p.parent_id in (
SELECT partyId FROM (SELECT
p.id AS partyId,
p.parent_id AS parentId,
pul.username AS userName,
p.city,
p.birth_date AS birthDate,
p.phone AS telePhoneNo
FROM
party p
LEFT JOIN party_user_login pul ON pul.party_id = p.id
WHERE
1 = 1
AND p.parent_id = 57 ) AS secondLevelIds)
union all
SELECT
p.id AS partyId,
p.parent_id AS parentId,
pul.username AS userName,
p.city,
p.birth_date AS birthDate,
p.phone AS telePhoneNo
FROM
party p
LEFT JOIN party_user_login pul ON pul.party_id = p.id
WHERE 1=1 AND p.parent_id in (
select partyId FROM (SELECT
p.id AS partyId,
p.parent_id AS parentId,
pul.username AS userName,
p.city,
p.birth_date AS birthDate,
p.phone AS telePhoneNo
FROM
party p
LEFT JOIN party_user_login pul ON pul.party_id = p.id
WHERE 1=1 AND p.parent_id in (
SELECT partyId FROM (SELECT
p.id AS partyId,
p.parent_id AS parentId,
pul.username AS userName,
p.city,
p.birth_date AS birthDate,
p.phone AS telePhoneNo
FROM
party p
LEFT JOIN party_user_login pul ON pul.party_id = p.id
WHERE
1 = 1
AND p.parent_id = 57 ) AS secondLevelIds) )AS thirdLevelIds)