Home > Backend Development > PHP Tutorial > javascript - mysql 查七天的支付

javascript - mysql 查七天的支付

WBOY
Release: 2016-06-06 20:13:23
Original
1149 people have browsed it

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

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

回复内容:

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

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

<code>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 </code>
Copy after login

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

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

<code>select sum(todayPay) as subPay from paylog where date >= unix_timestamp(DATE_SUB(curdate(),INTERVAL 6 DAY))  group by uid</code>
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template