数据库中存的时间段是addtime,存的格式是时间戳,现在我要按星期统计出users表,如图:
使用MYSQL语句:
select DATE_FORMAT(from_unixtime(addtime),'%Y%m%u') as weeks,count(uid) as count from users group by weeks;
得出的结果:
,其中的from_unixtime是把时间戳改成普通时间格式,'%Y%m%u'是显示格式,哪年哪月第几个星期,更多格式看:
http://www.w3school.com.cn/sql/func_date_format.asp
按年,按季度,按月的什么的,依葫芦画瓢,应该可以~