我有一个包含用户ID,IP地址和登录日期时间的日志表。我需要通过设置多个帐户来找出谁是假冒其他用户的用户。
这是我的示例日志表:
+---------+-------------+---------------------+
| user id | ip address | log in datetime |
+---------+-------------+---------------------+
| 17 | 192.168.1.4 | 2012-04-01 00:01:00 |
+---------+-------------+---------------------+
| 21 | 192.168.1.2 | 2012-04-01 00:02:00 |
+---------+-------------+---------------------+
| 11 | 192.168.1.5 | 2012-04-01 00:06:00 |
+---------+-------------+---------------------+
| 1 | 192.168.1.3 | 2012-04-01 00:09:00 |
+---------+-------------+---------------------+
| 3 | 192.168.1.3 | 2012-04-01 00:15:00 |
+---------+-------------+---------------------+
| 8 | 192.168.1.5 | 2012-04-01 00:22:00 |
+---------+-------------+---------------------+
| 9 | 192.168.1.1 | 2012-04-01 00:26:00 |
+---------+-------------+---------------------+
| 13 | 192.168.2.1 | 2012-04-01 00:27:00 |
+---------+-------------+---------------------+
| 2 | 192.168.1.1 | 2012-04-01 00:28:00 |
+---------+-------------+---------------------+
| 33 | 192.168.1.7 | 2012-04-01 00:30:00 |
+---------+-------------+---------------------+
| 27 | 192.168.1.1 | 2012-04-01 00:31:00 |
+---------+-------------+---------------------+
| 22 | 192.168.1.7 | 2012-04-01 00:45:00 |
+---------+-------------+---------------------+
所以,这是我的问题:如何选择一个具有相同IP地址且登录时间差小于5分钟的用户ID列表?
最佳答案
这样的事情怎么样-
SELECT *
FROM log l1
INNER JOIN log l2
ON l1.ip_address = l2.ip_address
AND l1.user_id < l2.user_id
AND l1.login _time BETWEEN (l2.login_time - INTERVAL 5 MINUTE) AND (l2.login_time + INTERVAL 5 MINUTE)
关于mysql - 捕捉沙袋,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10041910/