【发布时间】:2015-08-19 11:46:15
【问题描述】:
我有一张桌子total_count
id studid month year acls_id total_p total_a
1 30 08 2015 12 5 2
2 35 08 2015 12 5 2
3 52 08 2015 12 5 2
4 53 08 2015 12 5 2
5 54 08 2015 12 5 2
6 55 08 2015 12 5 2
7 30 09 2015 12 3 0
8 35 09 2015 12 3 0
9 52 09 2015 12 2 1
10 53 09 2015 12 3 0
11 54 09 2015 12 3 0
12 55 09 2015 12 3 0
我想为每个学生计算total_p 和total_a。
例如:studid = 30、total_p = 5 和 total_a = 2。
所以我想得到每个 studid 的每个月的总和以及总月数的 total_p 和 total_a 的总和。
我的控制器代码是
$total_counts = DB::table('total_count')
->whereBetween('smonth',08, 09))
->whereBetween('syear', 2015, 2015))
->sum('total_p);
->sum('total_a);
查看blade.php
{{$total_counts->total_p}}
{{$total_counts->total_a}}
但它不起作用..
如何在查询生成器格式中使用sum()?
我想要这样的输出:
studid total_p total_a
30 8 2
35 8 2
52 7 3
53 8 2
54 8 2
55 8 2
【问题讨论】:
标签: php mysql laravel laravel-4 eloquent