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

∫`不撒娇的折耳猫 2020-9-14 1945

         $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']);
        }

查询结果展示:

最新回复 (0)
发新帖