gpt4 book ai didi

mysql - 我的查询在 mysql 中工作,但不适用于 laravel eloquent

转载 作者:行者123 更新时间:2023-11-29 21:14:12 25 4
gpt4 key购买 nike

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

最佳答案

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

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

关于mysql - 我的查询在 mysql 中工作,但不适用于 laravel eloquent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36101821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com