当有统计每天的数据条数的时候,可以直接一句sql语句实现
比如字段updated_at是时间日期格式,那么DATE_FORMAT(updated_at,'%Y-%m-%d') as day 配合group by day 就能实现
select DATE_FORMAT(updated_at,'%Y-%m-%d') as day ,count(*) as num from visitor group by day order by day desc limit 30
如果是时间戳格式
FROM_UNIXTIME(create_time,'%Y-%m-%d') as day