select distinct a.id as 部门编码,a.name as 部门名称,d.userName,d.realName from fine_department a
left join fine_dep_role b on a.id=b.departmentId
left join fine_user_role_middle c on b.id=c.roleId
join fine_user d on c.userId =d.id
where b.id in (select roleId from fine_user a
left join fine_user_role_middle b on a.id=b.userId
where realName='$fine_username'
and b.roleType=1)
藏的实在是太深了。主要的关联关系如上。