好的,我想找到所有具有相同值的行.(或者至少一对)
IE
James| 19.193.283.19
John| 20.134.232.344
Jack| 19.193.283.19
Jonny| 19.193.283.19
Run Code Online (Sandbox Code Playgroud)
我希望它返回James,Jack和Jonny的行 - 其中不止一行有IP '19 .193.283.19'.
我尝试做其他类似问题的答案:
select *
from `Zombie`
group by `Ip`
having count(*) > 1
order by `Ip` desc
Run Code Online (Sandbox Code Playgroud)
但是它只返回了一排有一对或更多相似的'Ip'我想要的每一行.
我如何修改SQL,以便返回所有的indisinct行?
非常感谢.
您可以使用exists子查询来查找具有相同行的相同行Ip:
select *
from YourTable as yt1
where exists
(
select *
from YourTable as yt2
where yt1.name <> yt2.name
and yt1.Ip = yt2.Ip
)
Run Code Online (Sandbox Code Playgroud)
使用相同的行数排序Ip可以使用自联接进行排序,例如:
select yt1.name
, yt1.Ip
from YourTable as yt1
join YourTable as yt2
on yt1.name <> yt2.name
and yt1.Ip = yt2.Ip
group by
yt1.name
, yt1.Ip
order by
count(yt2.name) desc
Run Code Online (Sandbox Code Playgroud)