<p>Given a table of votes (users vote for a choice, and must supply an email address):</p>

<pre><code>votes
--
id: int
choice: int
timestamp: timestamp
ip: varchar
email: varchar
</code></pre>

<p>What's the best way to count "unique" votes (a user being a unique combination of email + ip) given the constraint they may only vote <em>twice</em> per hour?</p>

<p>It's possible to count the number of hours between first and last vote and determine the maximum number of allowed votes for that timeframe, but that allows users to compress all their votes into say, a single hour-long window, and still have them counted.</p>

<p>I realize anonymous online voting is inherently flawed, but I'm not sure how to do this with SQL. Should I be using an external script or whatever instead? (For each choice, for each email+ip pair, get a vote, calculate the next +1h timestamp, count/discard/tally votes, move on to the next hour, etc...)</p>

Something like
```
```
select email, ip, count(choice)
from votes
group by email, ip, datepart(hour, timestamp)
```
```
If I understand correctly