请教一个sql查询的问题,高手指点,谢谢....
答案:3 悬赏:30 手机版
解决时间 2021-03-05 23:58
- 提问者网友:暗中人
- 2021-03-05 00:17
请教一个sql查询的问题,高手指点,谢谢....
最佳答案
- 五星知识达人网友:鱼忧
- 2021-03-05 01:17
1,select username, powername from tbuser u,tbuserrole ur,tbrole r where u.id=ur.user_id and ur.role_id=r.id
用到三张表
2,select username, powername from tbuser u,tbuserrole ur,tbrolepower rp,tbpower p where u.id=ur.user_id and ur.role_id=rp.role_id and rp.power_id=p.id
角色表(tbrole)可以省略过
3,用户角色信息的权限信息一起给你查找出来:
select username,rolename, powername from tbuser u,tbuserrole ur,tbrole,tbrolepower rp,tbpower p where u.id=ur.user_id and ur.role_id=r.id and ur.role_id=rp.role_id and rp.power_id=p.id
同样的问题?都是我回答的没问题把?
用到三张表
2,select username, powername from tbuser u,tbuserrole ur,tbrolepower rp,tbpower p where u.id=ur.user_id and ur.role_id=rp.role_id and rp.power_id=p.id
角色表(tbrole)可以省略过
3,用户角色信息的权限信息一起给你查找出来:
select username,rolename, powername from tbuser u,tbuserrole ur,tbrole,tbrolepower rp,tbpower p where u.id=ur.user_id and ur.role_id=r.id and ur.role_id=rp.role_id and rp.power_id=p.id
同样的问题?都是我回答的没问题把?
全部回答
- 1楼网友:佘樂
- 2021-03-05 04:15
select a.username,c.rolename
from tbuser a
left join tbuserrole b
on a.id=b.user_id
left join tbrole c
on b.role_id=c.id
select a.username,e.powername
from tbuser a
left join tbuserrole b
on a.id=b.user_id
left join tbrole c
on b.role_id=c.id
left join tbrolepower d
on c.id=d.role_id
left join tbpower e
on d.power_id=e.id
from tbuser a
left join tbuserrole b
on a.id=b.user_id
left join tbrole c
on b.role_id=c.id
select a.username,e.powername
from tbuser a
left join tbuserrole b
on a.id=b.user_id
left join tbrole c
on b.role_id=c.id
left join tbrolepower d
on c.id=d.role_id
left join tbpower e
on d.power_id=e.id
- 2楼网友:孤独的牧羊人
- 2021-03-05 02:43
1、select rolename from tbrole where id=(select role_id from tbuserrole where user_id=(select id from tbuser where username=****))
2、select powername from tbpower where id in(select power_id from tbrolepower where id=(select role_id from tbuserrole where user_id=(select id from tbuser where username=****)))
2、select powername from tbpower where id in(select power_id from tbrolepower where id=(select role_id from tbuserrole where user_id=(select id from tbuser where username=****)))
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯