<?php
//根据日期来统计所消耗的点数 //模型的使用方法 $result = $model ->field("id,FROM_UNIXTIME(createtime,'%Y-%m-%d') as `createtime`,sum(price) as count_price") ->group("FROM_UNIXTIME(createtime,'%Y-%m-%d'),store_id") ->order('createtime desc') ->paginate(10); //注意如果使用了paginate分页 group就要用原函数写不然就找不到改字段 //Db类的使用方法,可以用子查询,这样分页的group就不用函数定义了 $bulidSql = Db::name('table')->field("id,FROM_UNIXTIME(createtime,'%Y-%m-%d') as `group_time`,sum(price) as count_price")->group("group_time")->buildSql();
$result = Db::table($bulidSql.' spl')->fetchSql(false)->paginate();
//或者
$result = Db::table($bulidSql)->alias("spl")->fetchSql(false)->paginate();
//带where查询,可以看手册,有闭包查询方便
$result = Db::table($bulidSql)->alias("spl")->where('spl.group_time','2023-08-28')->fetchSql(false)->paginate();
原数据
FROM_UNIXTIME之后的数据
group by 后的数据
- thinkphp5 thinkphp paginate 日期 groupthinkphp5 thinkphp paginate日期 thinkphp5 thinkphp group thinkphp5 thinkphp5 weblogic thinkphp thinkphp5框架thinkphp数据库 htmlentities thinkphp5 parameter thinkphp thinkphp5 thinkphp接口 数据 漏洞分析 漏洞thinkphp5 thinkphp thinkphp thinkphp3 thinkphp5常用 postgresql thinkphp5 thinkphp model