mysql统计当天消费总额

时间:2024年03月02日

/

来源:网络

/

编辑:佚名

addtime是时间字段
shop是数据表
subtotal要统计的字段
select * from shop where DATE_FORMAT(addtime,'%Y-%m-%d')=to_days(now()) group by addtime;
$daybegin=strtotime(date('Y-m-d'));
$dayend=$daybegin+86400;
sql="select sum(subtotal)  as pay from shop where addtime < $dayend and addtime > $daybegin group by FROM_UNIXTIME(addtime,'%y-%m-%d')";
print_r($sql);
打印如下sql语句;
select sum(subtotal) from shop where addtime < 1477238400 and addtime > 1477152000 group by FROM_UNIXTIME(addtime,'%y-%m-%d')
<?php
$daybegin=strtotime(date('Y-m-d'));
$dayend=$daybegin+86400;
//查询当天的数据
sql="select * from my_money where time < $dayend and time > $daybegin";
//统计当天支出总额
sqlout="select sum(cash) as cashout from my_money where time < $dayend and time > $daybegin and type=1";
//统计当天收入总额
sqlin="select sum(cash) as cashin from my_money where time < $dayend and time > $daybegin and type=2";
猜你需要

豫ICP备2021026617号-1  豫公网安备:41172602000185   Copyright © 2021-2028 www.78moban.com/ All Rights Reserved

本站作品均来自互联网,转载目的在于传递更多信息,并不代表本站赞同其观点和对其真实性负责。如有侵犯您的版权,请联系 1565229909#qq.com(把#改成@),我们将立即处理。