我想统计一下每个月注册的新生人数和在线学生的数量。我想要这样的产出:
所需输出
"month" "total"
--------------
"Jan" "0"
"Feb" "0"
"Mar" "0"
"Apr" "0"
"May" "0"
"Jun" "22"
"Jul" "0"
"Aug" "30"
"Sep" "0"
"Oct" "0"
"Nov" "0"
"Dec" "0"但返回的结果是:Output
"month" "total"
--------------
"Jun" "22"
"Aug" "30"这是我的密码
$getTotalOnl = Member::select(
DB::raw('IFNULL(count(id),0) as count'),
DB::raw('YEAR(updated_at) year, MONTH(updated_at) month')
)->whereBetween('updated_at', [$from, $to])->groupby('year','month')->get()->toArray();
dd($getTotal);发布于 2019-10-04 03:47:44
试试下面的代码:
public function register() {
$month = 12
totalStudents = [];
for($i = $month; $i > 0; $i--) {
$students = Student::whereMonth('created_at', $i)->get();
totalStudents[] = $i . '=' . $students->count();
}
dd($totalStudents);
}$i表示$i = 01 it表示为january的日期,您可以创建该逻辑。
https://stackoverflow.com/questions/58229575
复制相似问题