首页 > mysql 查七天的支付

mysql 查七天的支付

paylog表 date userid todayPay
现在我要查一个sevenDayPay

就是加上每个date每个uid的近七天支付之和,最好一个sql能搞定


SELECT * FROM article WHERE date_sub(curdate(), INTERVAL 7 DAY) <= DATE(add_time);
可以参考PHP程序员雷雪松的博客:http://www.leixuesong.cn/2065


你需要的是一个函数subdate()


select sum(todayPay) as subPay from paylog where date >= unix_timestamp(DATE_SUB(curdate(),INTERVAL 6 DAY))  group by uid

当然了,如果你要配合php,可以计算出当前时间减去7天/6天 的时间戳,然后放入sql替换就可以了/


select *,(select sum(todayPay) from paylog where date between (pa.date- interval 7 day) and pa.date and uid=pa.uid) as subPay from paylog pa 

好像是这样的。 (谢谢rebiekong的提醒)

【热门文章】
【热门文章】