0

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 行;

4

1 回答 1

0

我认为您忘记将查询结果分配给变量:

$studentsQuery = \FeeModal::query();
$studentsFee = $studentsQuery->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' );
于 2016-03-20T00:15:50.253 回答