我不熟悉 vBulletin 的数据库结构,但你应该这样做,假设你的用户表有一个日期/日期时间/时间戳created_date
或reg_timestamp
列或类似的东西,使用MySQL 的YEAR()和MONTH()函数。
select
count(*) as count,
year(reg_timestamp) as year
month(reg_timestamp) as month
from users
group by year, month;
这将导致与此类似的事情:
+-------+-------+------+
| count | month | year |
+-------+-------+------+
| 4 | 11 | 2008 |
| 1 | 12 | 2008 |
| 196 | 12 | 2009 |
| 651 | 1 | 2010 |
+-------+-------+------+
编辑:关于 Dave 的评论: vBulletin 的日期似乎以 Unixtime 格式存储。在这种情况下,只需将列包装起来即可FROM_UNIXTIME
将其转换为可读的 MySQL 日期:
select
count(*) as count,
year(from_unixtime(reg_timestamp)) as year
month(from_unixtime(reg_timestamp)) as month
from users
group by year, month;