欢迎各位兄弟 发布技术文章
这里的技术是共享的
这个例子是对课程进度表里面的某个学生的剩余课时进行求和汇总。
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 fromstudent_lesson_progress
wherestudent_info_id
= ?”
“bindings” => array:1 [▶]
“time” => 51.48
]
]
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();
来自 https://blog.csdn.net/zhezhebie/article/details/80322100