with topdp(id,supdepid,departmentmark,orgid) as (
select id,a.supdepid,a.departmentmark,id as orgid
from hrmdepartment a
union all
select a.id,a.supdepid,a.departmentmark,b.orgid
from hrmdepartment a inner join topdp b on a.id = b.supdepid
)
select orgid,id as topid from topdp where supdepid=0
请在评论区留言,共同探讨~~~
如有需要,请联系微信:hdygzh2019 同时请说明来意,共同进步!!!