我想计算每个月有多少用户创建帐户,我在这里找到一个查询-作者说它对他有效,但是我有问题-正如我所说的-第3个参数始终为0。
我试图通过多种方式(删除,添加args)对其进行修复,但结果相同或SQL错误。
SELECT y, m, Count(ytskagamerpl_userinfo.creationdate)
FROM (
SELECT y, m
FROM
(SELECT YEAR(CURDATE()) y UNION ALL SELECT YEAR(CURDATE())-1) years,
(SELECT 1 m UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8
UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12) months
) ym
LEFT JOIN ytskagamerpl_userinfo
ON ym.y = YEAR(FROM_UNIXTIME(ytskagamerpl_userinfo.creationdate))
AND ym.m = MONTH(FROM_UNIXTIME(ytskagamerpl_userinfo.creationdate))
WHERE (y=YEAR(CURDATE()) AND m<=MONTH(CURDATE()))
OR
(y<YEAR(CURDATE()) AND m>MONTH(CURDATE()))
GROUP BY y, m;
数据库:
uid | creationdate (TIMESTAMP):
1 | 20.10.2018
2 | 12.11.2018
... | ..........
X | 15.07.2019
PHP VAR DUMP _ https://pastebin.com/ABT5PCZn
我希望在X月201X年创建的用户数,但始终返回0, 年和月正确显示。