sql語句查詢上下級信息

/*查找邀請碼爲5TU422全部的下級*/
WITH T AS(
SELECT
invitation_code,
inviter_invitation_code,
user_name,
0 L
FROM
axc_users
WHERE
invitation_code = '5TU422'
UNION ALL
SELECT
U.invitation_code,
U.inviter_invitation_code,
U.user_name,
L + 1
FROM
axc_users U
INNER JOIN T ON
U.inviter_invitation_code = T.invitation_code )
SELECT *FROM T
code

 


/*查找邀請碼爲5TU422全部的上級*/
WITH T AS(
SELECT
invitation_code,
inviter_invitation_code,
user_name,
0 L
FROM
axc_users
WHERE
invitation_code = '5TU422'
UNION ALL
SELECT
U.invitation_code,
U.inviter_invitation_code,
U.user_name,
L + 1
FROM
axc_users U
INNER JOIN T ON
U.invitation_code = T.inviter_invitation_code ) SELECT
*
FROM
Tit

相關文章
相關標籤/搜索