这个例子是对课程进度表里面的某个学生的剩余课时进行求和汇总。
laravel 版本是 lts 5.5
StudentLessonProgress::where('student_info_id', $student_info_id)
->sum('total_left_class_num');
dayinsql语句如下:
array:1 [▼
0 => array:3 [▼
“query” => “select sum(total_left_class_num
) as aggregate fromstudent_lesson_progress
wherestudent_info_id
= ?”
“bindings” => array:1 [▶]
“time” => 51.48
]
]
二、需要多个sum
laravel中怎么实现下面的SQL
select sum(‘profit’),sum(‘order_count’) from products where……;
参考
Product::where('status',1)->first(
array(
\DB::raw('SUM(profit) as profit'),
\DB::raw('SUM(order_count) as order_count')
)
)->toArray();