我想计算同月投票的人数
我的表看起来像:
Table_votes
ID
Person_ID
voteitem_ID
vote
Date
表格中的数据如下所示:
1 1 1 2/2/2012
2 1 2 2/2/2012
3 2 1 3/3/2012
4 2 2 3/3/2012
5 3 1 2/12/2012
6 3 2 2/12/2012
我希望查询输出的是2个人在第2个月投票,1个人在第3个月投票
答案 0 :(得分:2)
select count(person_id) as person_count
month(Date) as Month
from table_votes
group by month(Date)
答案 1 :(得分:1)
如果您的数据超过一年,则需要考虑到这一点。
试
select
count(distinct person_id) as count_personID,
year(date) as yr,
month(date) as mo
from
table_votes
group by
year(date),
month(date)