Laravel 对某一列进行筛选然后求和sum()的例子

2025-05-29 0 27

这个例子是对课程进度表里面的某个学生的剩余课时进行求和汇总。

laravel 版本是 lts 5.5

?

1

2
StudentLessonProgress::where('student_info_id', $student_info_id)

->sum('total_left_class_num');

打印sql语句如下:

?

1

2

3

4

5

6

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

参考

?

1

2

3

4

5

6
Product::where('status',1)->first(

array(

\\DB::raw('SUM(profit) as profit'),

\\DB::raw('SUM(order_count) as order_count')

)

)->toArray();

以上这篇Laravel 对某一列进行筛选然后求和sum()的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持快网idc。

原文链接:https://blog.csdn.net/zhezhebie/article/details/80322100

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 Laravel 对某一列进行筛选然后求和sum()的例子 https://www.kuaiidc.com/91334.html

相关文章

发表评论
暂无评论