有没有人知道如何查询 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 的数据库结构,但你应该做类似这样的事情,假设你的用户表有一个日期/日期时间/时间戳 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;
关于php - 如何编写一个 SQL 查询来计算每月和每年的行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5040141/