作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个名为 votes
的数据库表,其中包含三列“timestamp”、“voter”和“voted_for”。
表中的每个条目代表一票。我想在某些条件下计算每个“voted_for”的所有选票。
条件如下:
每个选民只能投票一次,如果一个选民投了多票,则以最近的一票为准。
只计算在指定时间之前进行的投票。
最佳答案
试试这个:
SELECT voted_for, count(*)
FROM votes v
INNER JOIN (SELECT Voter, Max(timestamp) as lastTime from votes group by Voter) A
on A.Voter = v.voter and a.lasttime = v.timestamp
WHERE timestamp < {date and time of last vote allowed}
Group by voted_for
关于sql - 我如何在 MySQL 中统计选票?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4219022/
我是一名优秀的程序员,十分优秀!