I have a table 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
I want to calculate for each student total_p and total_a.
eg: studid = 30, total_p = 5 and total_a = 2.
So I'd like to get the total of each month for each studid and a sum of total_p and total_a for the total months.
My controller code is
$total_counts = DB::table('total_count')
->whereBetween('smonth',08, 09))
->whereBetween('syear', 2015, 2015))
->sum('total_p);
->sum('total_a);
view blade.php
{{$total_counts->total_p}}
{{$total_counts->total_a}}
but it doesn't work..
How to use sum() in query builder format?
I would like an output like:
studid total_p total_a
30 8 2
35 8 2
52 7 3
53 8 2
54 8 2
55 8 2