ThinkPHP5开发:查询近一年每个月的总和

2023-01-1808:44:45后端程序开发Comments1,243 views字数 775阅读模式
 $lastYearNums $apply
            ->field(['CONCAT(date_format(from_unixtime(create_time),\'%Y\'),"-",date_format(from_unixtime(create_time),\'%m\'))' =>'yearmonth','count("id") as total'])
            ->where('(date_format(from_unixtime(create_time),\'%Y\')>'.$yearStart.' or (date_format(from_unixtime(create_time),\'%Y\')='.$yearStart.' and date_format(from_unixtime(create_time),\'%m\')>'.$monthStart.'))')
            ->group('yearmonth')
            ->select();
        dump($lastYearNums->toArray());exit;
        $arrYearMonth = [];
        $arrMonthTotal = [];
        foreach ($lastYearNums as $key => $itemNums){
            array_push($arrYearMonth,date('Y-m',strtotime($itemNums['yearmonth'])));
            array_push($arrMonthTotal,$itemNums['total']);
        }

查询结果展示:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/30500.html

ThinkPHP5开发:查询近一年每个月的总和文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/30500.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/30500.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定