显示想要日期行的总记录

时间:2016-02-18 05:31:44

标签: php mysql

我通过汇总结果从表中检索数据并显示在表格中。我想在date =' 2014-01'之间显示总和结果记录。和日期=' 2014-04'在2014-04栏目名称。然后,我想在2014-05检索到当前日期的其他总和结果。 我怎么能这样做?

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 
DATE_FORMAT(`regist_timestamp`,'%Y/%m' )

1 个答案:

答案 0 :(得分:1)

SELECT上设置日期格式,然后GROUP BY。试试 -

SELECT MONTH(regist_timestamp) AS Month, YEAR(regist_timestamp) AS Year, 
count(id) AS numberOfVisits, DATE_FORMAT(`regist_timestamp`,'%Y/%m' ) formatted_date
FROM ash_members
WHERE DATE(regist_timestamp) < CURDATE()
GROUP BY formatted_date