mysql 查询验证防作弊系统

dfuffjeb  于 2022-11-28  发布在  Mysql
关注(0)|答案(2)|浏览(101)

我有一个表,基本上收集特定用户的投票:

ID | user_id | ip | timestamp

每次有人投票给一个用户,一个条目会被创建,记录他们投票给的user_id,他们的IP地址和时间和日期。为了防止作弊,我们不允许每个用户每天每个IP超过20票。
现在我想验证这些投票,从一个给定的日期开始,我自己提出了下面的问题,但我绝不是Maven,所以如果有人能告诉我,如果我有这个正确的,我将非常感谢。

SELECT count(*) As `votes`, user_id, ip, DATE( timestamp ) the_date
FROM `user_votes`
GROUP BY user_id, ip, the_date
HAVING the_date > '2012-07-26'
ORDER BY the_date ASC, user_id ASC, votes DESC
vybvopom

vybvopom1#

试试这个:

SELECT count(*) As `votes`, user_id, ip, DATE( timestamp ) the_date
FROM `user_votes`
where the_date > '2012-07-26'
GROUP BY user_id, ip, DATE( timestamp )
having count(*)>20 
ORDER BY DATE( timestamp ) ASC, user_id ASC, votes DESC

如果count(*)〉20,则计数将大于20

ozxc1zmp

ozxc1zmp2#

要获得拥有有效投票数的用户,您可以尝试以下操作:

SELECT COUNT(*) As `votes`, user_id, ip, DATE( timestamp ) the_date
FROM `user_votes`
WHERE DATE(timestamp ) > '2012-07-26'
GROUP BY user_id, ip, the_date
HAVING COUNT(*) <= 20
ORDER BY the_date ASC, user_id ASC, votes DESC;

相关问题