有没有人知道如何查询vBulletin数据库以生成每月/每年注册次数的报告,从而获得诸如..

MM/YYYY      Count
01/2001  :   10
02/2001  :   12
...
...

感谢下面的答案。我的最终版本如下:
SELECT
  COUNT(*) as 'Registrations',
  YEAR(FROM_UNIXTIME(joindate)) as 'Year',
  MONTH(FROM_UNIXTIME(joindate)) as 'Month'
FROM vbfuser
GROUP BY Year,Month

最佳答案

我不熟悉vbulletin的数据库结构,但是您应该这样做,假设您的用户表有一个date/datetime/timestampcreated_datereg_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 |
+-------+-------+------+

编辑:关于戴夫的评论: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;

10-05 23:20