Reputation: 508
I've a ams_marks
table. I want to get sum
value in a column from same roll and show all records with sum. I was try $this->db->group_by()
method but it show only single row under a roll. But I want to show all row with roll
sum result in a Obtain Mark
column using Position
column. How can I solve it by CodeIgniter
?
Upvotes: 0
Views: 628
Reputation: 325
Try this :
$sql = "SELECT * FROM ams_marks am
LEFT JOIN (
SELECT SUM(obtain_mark) as position,roll FROM ams_marks am_g
GROUP BY roll
) as ams_sum on ams_sum.roll = am.roll";
$result = $this->db->query($sql)->result_array();
It will populate the position field with the SUM of obtain mark.
Upvotes: 2