数据统计
ps:时间字段为时间戳
1、select DATE_FORMAT(from_unixtime(datetime),'%Y-%m-%d') days,sum(amount) as count,count(id) as num from 表名 WHERE date_format(from_UNIXTIME(`datetime`),'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') group by days ORDER BY days DESC //当天 2、SELECT * FROM 表名 WHERE TO_DAYS(date_format(now(),'%Y-%m-%d'))-TO_DAYS(date_format(from_UNIXTIME(`datetime`),'%Y-%m-%d')) = 1 //昨天 3、SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY)<= date(date_format(from_UNIXTIME(`datetime`),'%Y-%m-%d')) //近7天
时间字段为datetime
SELECT * FROM 表名 DATE_SUB(CURDATE(), INTERVAL 2 DAY) >= date_format(`时间字段`,'%Y-%m-%d');//2天前的数据