SELECT p1.*,p2.* FROM pe_dept p1
INNER JOIN
(SELECT * FROM pe_dept) AS p2
ON p1.`company_id`=p2.`company_id`
WHERE p1.company_id = 1 AND p2.dept_id = p1.parent_id
查询结果:
原表信息
SELECT p1.*,p2.* FROM pe_dept p1
INNER JOIN
(SELECT * FROM pe_dept) AS p2
ON p1.`company_id`=p2.`company_id`
WHERE p1.company_id = 1 AND p2.dept_id = p1.parent_id
查询结果:
原表信息