2012-08-02 21 views
0

我基本上收集選票特定用戶的表:查詢驗證防作弊系統

ID | user_id | ip | timestamp 

每當有人投票支持一個用戶,創建一個條目記錄他們投票支持,user_ID的他們IP地址和時間和日期。 爲了防止作弊,我們不允許每個用戶每IP每天超過20票。

現在我想驗證這些投票,從給定日期開始,我自己提出了以下查詢,但我絕不是專家,所以如果有人可以告訴我,如果我有這個正確的我將不勝感激。

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 
+0

我會做count(user_id)而不是count(\ *)。如果您有大量數據,count(\ *)可能會觸發一些性能問題 – TerenceJackson 2012-08-02 07:11:49

回答

0

試試這個:

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

0

要獲得用戶已經投票的有效數字,你可以試試這個:

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;