详情页

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";
相关文章
猜你需要