如何检索与第一个子查询匹配所有行的记录
您好,需要帮助来解决一些复杂的查询。我会将输入用户名(例如 test )发送到查询。我必须列出与用户名 test 具有相同角色的其他用户,并且这些用户名应该与用户名 test 的所有组 ID 相匹配。如果其他用户拥有的组数多于用户名 test 则不是问题,但应匹配用户名 test 中存在的所有 groupdid。我尝试了以下查询。如果所有 groupid 都匹配,它将不会返回任何行。但是,我需要与所有组 ID 匹配的用户名,而不是不返回完全匹配的行。
select
group_id
from
user_info us ,group_privilege_details gp
where
login_name='test'
and us.user_id = gp.user_id
EXCEPT
select
group_id
from
user_info u ,group_privilege_details g
where login_name !='test'
and role_id in (select role_id
from user_info
where login_name ='test')
and group_id in (select group_id
from user_info us ,group_privilege_details gp
where login_name='test'
and us.user_id = gp.user_id )
and g.user_id = u.user_id
提前致谢。抱歉很长的解释
Hi Need help to resolve some complicated query. I'll send the input username (say test ) to the query. I have to list the other users with the same role of the username test and also those usernames should be match with all the groupid of the username test. If the other user has more groups than username test is not an issue, but should match all the groupdid exists in the username test. I tried the following query. It wil return no rows if all the groupids matches. But, I need the username those who have match with all the group id instead of returning no rows for the exact match.
select
group_id
from
user_info us ,group_privilege_details gp
where
login_name='test'
and us.user_id = gp.user_id
EXCEPT
select
group_id
from
user_info u ,group_privilege_details g
where login_name !='test'
and role_id in (select role_id
from user_info
where login_name ='test')
and group_id in (select group_id
from user_info us ,group_privilege_details gp
where login_name='test'
and us.user_id = gp.user_id )
and g.user_id = u.user_id
Thanks in advance. And sorry for long explanation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,你想要:
在 SQL 中,类似于以下内容。我使用了以下缩写:OU 其他用户、TU 测试用户、TUG 测试用户组、OUG 其他用户组。
If I understand correctly you want:
In SQL that is something like the following. I used the following abbreviations: OU other user, TU test user, TUG test user's groups, OUG other user's groups.