我是SQL Server的新手,需要获得使用相同IP地址的不同用户组。
因此我得到了
我尝试自我加入table_x以获得具有相同IP地址的不同用户,但不幸的是结果不是我所期望的。
select *
from table_x x
join table_x y on (x.ip_address = y.ip_address and x.userId <> y.userId)
join users u on (x.userId = u.userId)
join usergroups ug on (ug.groupId = u.groupId)
提前致谢。
答案 0 :(得分:2)
要查找具有多个用户组的ip_addresses:
<script type="text/javascript">
//this is help check if postback by Server Button, if yes then invoke
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
function BeginRequestHandler(sender, args) {
if (args._postBackElement.id == '<%=ServerButton.ClientID%>')
$('#MyIFrame').load(function(){
InvokeJS('From Client');
console.log('load the iframe');
});
}
</script>
选择包含这些ip_addresses的组:
select x.ip_address
from table_x x
join usergroups ug on x.userId = ug.userId
group by ip_address
having count(distinct groupId) > 1
答案 1 :(得分:0)
要获得具有相同ip的多个用户的所有用户组,您可以使用以下语句:
select distinct ug.* from table_x join users u on (table_x.userId = u.userId) join
usergroups ug on (ug.userId = u.userId)
where exists (select 1 from table_x otherUser
where otherUser.ip_address = table_x.ip_address and otherUser.userId <> tablex.userId)