回复内容:
写了个DEMO,在线预览
先说下我用的时间格式是date,年-月-日
这种形式
统计次数,count再group by 列名
SELECT `periods`,DATE_FORMAT(time,'%Y-%m') as month,COUNT(*) AS `times` FROM `product` GROUP BY `periods`,`month` ORDER BY `month` DESC
登录后复制
DOC:
date_format:http://www.w3school.com.cn/sql/func_date_format.asp
group by:http://www.w3school.com.cn/sql/sql_groupby.asp
用count函数
用两个group by 条件就可以了呀
select count(id), periods, from_unixtime(time, '%Y-%m')
from product
where 你的条件
group by periods,from_unixtime(time, '%Y-%m')
登录后复制
呃,大概思路是这个样子的
select periods,sum(periods) as count from product where month>='时间' and mouth