MySQL:多表关联查询

select a.id,a.role_name,b.role_1 as ifTrue from sys_role a left join 
(
#用户组角色
select ugrr.permission_policy_id as role_1 from user_group_ref_role ugrr 
where ugrr.group_id in (
  select ugr.group_id from user_group_ref ugr where ugr.user_id = 1115358335685574732 and ugr.is_deleted = 0 ) 
  and ugrr.is_deleted = 0 
  union
#职位角色
select spr.role_id as role_2 from sys_post_role spr 
where spr.post_id in (
  select sup.post_id from sys_user_post sup where sup.user_id = 1115358335685574732 and sup.is_deleted = 0)
and spr.is_deleted = 0 
union
#用户角色
select urr.permission_policy_id as role_3 from user_ref_role urr
where urr.user_id = 1115358335685574732 and urr.is_deleted = 0
#部门角色
union
select sor.role_id as role_4 from sys_org_role sor
where sor.org_id in
(SELECT d3.id
    FROM ( 
        SELECT @r AS id, 
          (SELECT @r := pid FROM sys_organization WHERE id = @r) AS tmp_pid
        FROM (SELECT @r := (select suo.org_id from sys_user_organization suo where suo.user_id = 1115358335685574732)) leafNodeId, 
             sys_organization hd) d2 
    INNER JOIN sys_organization d3 ON d2.id = d3.id AND d2.tmp_pid is not null AND d3.is_deleted = 0
ORDER BY d3.id 
)and sor.is_deleted = 0 ) b on a.id = b.role_1  
where 
a.is_deleted = 0
and a.role_name like concat('%', 'SYS', '%')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值