select distinct mr.id,ifnull(mr.pid,0) as pid,mr.name
from sys_role_res srr
left join main_res mr on mr.id=srr.res_id
left join sys_role sr on sr.id=srr.role_id
left join bas_member_role bmr on bmr.role_id=sr.id
left join bas_member bm on bmr.member_id=bm.id
where bm.id = 4
and mr.is_delete = 0
and ifnull(mr.permission,0) = 0
order by mr.id
select distinct 查询值name from 表 where 条件