💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
这个例子是对课程进度表里面的某个学生的剩余课时进行求和汇总。 ## laravel 版本是 lts 5.5 ``` StudentLessonProgress::where('student_info_id', $student_info_id) ->sum('total_left_class_num'); ``` 打印sql语句如下: ``` array:1 [▼ 0 => array:3 [▼ “query” => “select sum(total_left_class_num) as aggregate from student_lesson_progress where student_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(); ```