Laravel 查询:
$studentsFee = \FeeModal::query();
$studentsFee->groupBy('main_campus_id', 'session_id', 'class_info_id', 'section_id', 'stage_id')
->selectRaw('count(student_id) as student_strength,SUM(IF(paid_amount>0,1,0)) as submit_students,SUM(IF(paid_amount=0,1,0)) as not_submit_students, sum(paid_amount) as submit_amount')
->with('sessionMode', 'section', 'classInfo', 'stage')->get();
dd(count($studentsFee). ' Records' );
结果:0 条记录
生成查询->toSql();
string(281) "select count(student_id) as student_strength,SUM(IF(paid_amount>0,1,0)) as submit_students,SUM(IF(paid_amount=0,1,0)) as not_submit_students, sum(paid_amount) as submit_amount from `fee` group by `main_campus_id`, `session_id`, `class_info_id`, `section_id`, `stage_id`"
当我在 mysql 中执行这个查询时,它返回 18 行;