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

 

相关文章:

  • 2022-12-23
  • 2021-11-26
  • 2021-12-10
  • 2021-08-26
  • 2021-11-27
  • 2022-12-23
  • 2021-08-06
  • 2021-09-25
猜你喜欢
  • 2022-12-23
  • 2021-10-17
  • 2021-06-24
  • 2021-05-01
  • 2021-08-28
  • 2021-11-23
  • 2022-12-23
相关资源
相似解决方案