简体   繁体   English

MySQL查询将查找使用相同IP地址的多个用户名的用户

[英]MySQL Query that will find users using the same IP Address for multiple usernames

I've done some homework on this issue and I am pretty sure it will involve joining a table with itself but I'm not quite there yet. 我已经在这个问题上做了一些功课,我很确定它会涉及将一个表本身连接起来,但是我还没有到位。

I have a forum with a "posts" table. 我有一个带有“帖子”表的论坛。 It stores the ipaddress, username, userid, and postid for every post made on the forum. 它存储在论坛上发布的每个帖子的ipaddress,用户名,userid和postid。

I am trying to get a query I can run each week or so that will output me a list of ipaddresses that have been used by multiple userids during this time- and the postids involved where the same ipaddress was used by multiple userids. 我正在尝试获取一个查询,该查询可以每周运行一次,这样将向我输出一个列表,其中列出了这段时间内多个用户ID已使用的ipaddress,以及涉及多个用户id使用相同ipaddress的postid。

I've got this so far from other people's similar questions here: 我到目前为止还没有其他人的类似问题:

SELECT t1.userid,t2.userid, t1.username, t2.username, t1.ipaddress, t2.ipaddress, t1.postid, t2.postid
FROM qvb_post t1
INNER JOIN qvb_post t2 ON t1.ipaddress=t2.ipaddress AND t1.userid!=t2.userid
WHERE 
t1.dateline > 1335897698 AND t2.dateline > 1335897698

But it returns a lot of unnecessary rows IMO, fr example it returns each duplicate both ways- both as if userid 1 used userid 2's ipaddress and again as if userid2 used userid1's address. 但是它返回了很多不必要的行IMO,例如,它以两种方式返回每个重复项-好像用户ID 1使用用户ID 2的ipaddress,又好像用户ID 2使用用户ID1的地址。

The dateline is from a few days ago. 日期截止日期是几天前。

Ideally I'd like to just see a list of ip addresses in order with the duplicate usernames and repeated for each post, so I can go in with PHP and make a report that outputs an IP Address, the usernames (userids) that used it, and the postids created by them. 理想情况下,我只想按顺序查找IP地址列表,并使用重复的用户名并在每篇文章中重复使用,因此我可以使用PHP并制作一个报告,以输出IP地址,使用该IP地址的用户名(用户ID) ,以及它们创建的postid。

I am aware that there are many valid reasons two people will have the same ip address, rest assured no harsh action would be taken against anyone merely for showing up in this report. 我知道,两个人拥有相同的IP地址有很多正当的理由,请放心,不会仅仅因为出现在此报告中而对任何人采取严厉的行动。

Thank you in advance for any help you can provide. 预先感谢您提供的任何帮助。

Just to be clear I'm fine with the PHP, it's only the Query I need help with. 为了清楚起见,我对PHP很好,这只是我需要帮助的查询。

This should give you a start: 这应该给您一个开始:

SELECT ipaddress, GROUP_CONCAT(DISTINCT username)
FROM qvb_post
GROUP BY ipaddress
HAVING COUNT(DISTINCT username) > 1
ORDER BY COUNT(DISTINCT username) DESC

It shows you IP addresses used by more than one distinct user name, and also gives you a comma separated list of those user names for each IP address. 它显示了多个不同用户名使用的IP地址,并且还为您提供了每个IP地址这些用户名的逗号分隔列表。 You could extend it to also include the post IDs if you wish. 如果需要,您可以扩展它以包含帖子ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM