0

我想统计当月投票的人数

我的桌子看起来像:

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 人投票,第 3 个月有 1 人投票

4

2 回答 2

2
select count(person_id) as person_count
       month(Date) as Month
from table_votes
group by month(Date)
于 2012-09-06T20:35:15.027 回答
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)
于 2012-09-06T20:53:03.133 回答