我正在尝试从我的主查询中加入 users_groups,但我似乎无法在别名表中加入它们。请帮我。它导致错误:“on 子句”中的未知列“node.id”
SELECT node.id, node.first_name, node.last_name, (COUNT( parent.id ) - ( sub_tree.depth +1 ) ) AS depth
FROM users AS node, users AS parent, users AS sub_parent, (
SELECT node.id, node.first_name, node.last_name, (COUNT( parent.id ) -1) AS depth
FROM users AS node, users AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.id =1
GROUP BY node.id
ORDER BY node.lft
) AS sub_tree
JOIN users_groups ON users_groups.user_id = node.id
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt
AND sub_parent.id = sub_tree.id
GROUP BY node.id
ORDER BY node.lft
LIMIT 0 , 30