使用MySQL,我有一个简单的表,用来记录用户登录时使用的IP地址:
TableIPLog
------------
ColumnID (primary key)
ColumnUserID (the ID of the user)
ColumnIP (the IP address the user used to login)我想要一个查询,将找到已共享IP地址的用户!
为了清楚起见,我希望查询只显示IP地址已被超过1个成员使用的行。
我被难住了。
发布于 2012-06-15 03:58:42
你可以走这条路,这是针对SQL-Server的,但我确信有一个mysql等价物:
select ColumnIP, count(*)
from TableIPLog
group by ColumnIP
having count(*) > 1然后,您可以使用这些ip来查找与其关联的用户名...
编辑:考虑到这一点,它可能不会工作,这取决于您的日志实现,但它不会花太多的时间让它工作……也许使用exists子句...
发布于 2012-06-15 10:14:36
SELECT a.id,a.userid,a.ip
FROM ip_log a inner join ip_log b
ON a.userid<>b.userid and a.ip=b.ip;这将列出具有相同ip但不同用户ip的所有用户ip和ip。
发布于 2012-06-15 04:03:56
我建议您这样存储IP(请查看this link):
mysql> SELECT INET_ATON('192.168.0.10') AS ipn;
+------------+
| ipn |
+------------+
| 3232235530 |
+------------+
mysql> SELECT INET_NTOA(3232235530) AS ipa;
+--------------+
| ipa |
+--------------+
| 192.168.0.10 |
+--------------+要进行搜索应该是这样的:
select INET_NTOA(columnIp), count(*) from tableIPLOG group by columnIp having count(*)>1https://stackoverflow.com/questions/11040423
复制相似问题