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";
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";
新闻资讯 更多
- 【mysql教程】mysql出现提示Table is marked as crashed and should be repaired 解决办法04-02
- 【mysql教程】 mysql实现不存在就Insert into存在则update举例03-30
- 【mysql教程】INSERT 表名(字段) VALUES(字段值) ON DUPLICATE KEY UPDATE 条件语句实例03-30
- 【mysql教程】sql中ON DUPLICATE KEY UPDATE有什么用?03-30
- 【mysql教程】mysql实现不存在就 Insert into 存在则 update03-30
- 【mysql教程】MySQL 当记录不存在时insert,当记录存在时update03-30
- 【mysql教程】将INSERT INTO转换为UPDATE03-30
- 【mysql教程】sql技术 --insert 变 update03-30
猜你需要