sql多重嵌套子查询,求优化!!!!!
selectMenuTextfrommainmenuwherePermissionIDin(selectdistinctPermissionIDfromRole_Perm...
select MenuText from mainmenu where PermissionID in(
select distinct PermissionID from Role_Permission where RoleID
in (select RoleID from User_Roles where roleid
in (select RoleID from User_Roles where userid =
(select id from users where Account='seven')))) 展开
select distinct PermissionID from Role_Permission where RoleID
in (select RoleID from User_Roles where roleid
in (select RoleID from User_Roles where userid =
(select id from users where Account='seven')))) 展开
4个回答
展开全部
select mm.MenuText from
mainmenu mm,
Role_Permission rp,
user_roles ur,
users u
where mm.PermissionID = rp.PermissionID
and ur.roleid=rp.roleid
and ur.roleid=u.roleid
and Account='seven'
mainmenu mm,
Role_Permission rp,
user_roles ur,
users u
where mm.PermissionID = rp.PermissionID
and ur.roleid=rp.roleid
and ur.roleid=u.roleid
and Account='seven'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼主对 user_roles的嵌套好象是重复了一遍,以下sql,请参考
SELECT MenuText
FROM mainmenu mu
WHERE PermissionID EXISTS
(SELECT 1
FROM Role_Permission rp
WHERE mu.PermissionID = rp.PermissionID
AND EXISTS (SELECT 1
FROM User_Roles ur
WHERE rp.RoleID = ur.userid
AND ur.account = 'seven'))
SELECT MenuText
FROM mainmenu mu
WHERE PermissionID EXISTS
(SELECT 1
FROM Role_Permission rp
WHERE mu.PermissionID = rp.PermissionID
AND EXISTS (SELECT 1
FROM User_Roles ur
WHERE rp.RoleID = ur.userid
AND ur.account = 'seven'))
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select MenuText from mainmenu where PermissionID in(
select distinct PermissionID from Role_Permission where RoleID
in (select RoleID from User_Roles where userid =
(select id from users where Account='seven')))
select distinct PermissionID from Role_Permission where RoleID
in (select RoleID from User_Roles where userid =
(select id from users where Account='seven')))
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该可以用内连接 inner join。
mainmenu(PermissionID)--Role_Permission (PermissionID )
Role_Permission (RoleID )--User_Roles (roleid )
User_Roles (userid)--users (id )
where users .Account='seven'
mainmenu(PermissionID)--Role_Permission (PermissionID )
Role_Permission (RoleID )--User_Roles (roleid )
User_Roles (userid)--users (id )
where users .Account='seven'
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |