mysql 按年、按月、按天 统计

 $user_sql = "select year(from_unixtime(ref_date)) as year,month(from_unixtime(ref_date)) as month,SUM(cancel_user) as cancel_user,SUM(new_user) as new_user,user_source as all_user,count(distinct mid) as count_mp ";
        //订阅
        $subscription_user = Db::query($user_sql." from mr_user_summary_data where mid " . $subscription_where . $user_where . " group by year(from_unixtime(ref_date)), month(from_unixtime(ref_date))");
        //服务

以上代码自动按日期把每个月的数据统计起来(每个月的数据相加),并在显示年和月

 $income = Db::query("select UNIX_TIMESTAMP(edate) as edate,account_id,ad_type,sum(amount) as amount from mr_flow_income WHERE ".$income_where."  unix_timestamp(edate) between ".$satrttime." and ".$endtime." group by unix_timestamp(edate) ,account_id  order by unix_timestamp(edate) ASC");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值