码迷,mamicode.com
首页 > 数据库 > 详细

mysql根据用自己的邀请码查询该用户所有下级

时间:2019-06-21 18:22:29      阅读:389      评论:0      收藏:0      [点我收藏+]

标签:invite   level   根据   mysql   nbsp   order by   elf   ber   self   

SELECT
c.id,
c.pid,c.zid,
c.self_invite,m.level_define
from customer_member m,
(
SELECT
id,
pid,zid,
self_invite
FROM
(
SELECT
a1.id,a1.zid,
a1.invite_code pid,
a1.self_invite,
a2.invite_code p2id,
a3.invite_code p3id,
a4.invite_code p4id,
a5.invite_code p5id
FROM
customer a1
LEFT JOIN customer a2 ON (
a1.invite_code = a2.self_invite
)
LEFT JOIN customer a3 ON (
a2.invite_code = a3.self_invite
)
LEFT JOIN customer a4 ON (
a3.invite_code = a4.self_invite
)
LEFT JOIN customer a5 ON (
a4.invite_code = a5.self_invite
)
) al
WHERE
(
pid = ‘AUTYPM‘
OR p2id = ‘AUTYPM‘
OR p3id = ‘AUTYPM‘
OR p4id = ‘AUTYPM‘
OR p5id = ‘AUTYPM‘
) ) c WHERE m.cust_id = c.zid order by id ASC 

# ‘AUTYPM‘是该用户自己的邀请码

mysql根据用自己的邀请码查询该用户所有下级

标签:invite   level   根据   mysql   nbsp   order by   elf   ber   self   

原文地址:https://www.cnblogs.com/fanqie15/p/11066064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!