mysql统计当天消费总额

 

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";

 

//统计当天支出总额

$sql_out="select sum(cash) as cashout from my_money where time < $dayend and time > $daybegin and type=1";

 

//统计当天收入总额

$sql_in="select sum(cash) as cashin from my_money where time < $dayend and time > $daybegin and type=2";

 

posted @ 2016-10-23 15:59  八路逆袭寡妇村  阅读(1546)  评论(0编辑  收藏  举报
www.zxzidian.com