使用查询在datetime大于当前日期时检索总记录ID

时间:2016-02-17 13:44:57

标签: php mysql

如果每个月使用myquery,我想检索datetime小于当前日期的总记录ID。但是我无法检索它。我没有得到任何输出。日期结构是类似于&的日期时间#39; 2016-2-17 23:20:22'。那么,我该怎么做?

 SELECT  DATE_FORMAT('regist_timestamp','%Y-%m-%d') AS date, count(id) as numberOfVisits from  ash_members
where DATE_FORMAT('regist_timestamp','%Y-%m-%d')<=curdate()

1 个答案:

答案 0 :(得分:0)

您需要对计数结果进行分组。如果您想要每月分组结果,您可以这样做。

SELECT MONTH(regist_timestamp) AS Month, YEAR(regist_timestamp) AS Year, count(id) AS numberOfVisits
FROM ash_members
WHERE DATE(regist_timestamp) < CURDATE()
GROUP BY MONTH(regist_timestamp), YEAR(regist_timestamp)