Welcome Guest, Not a member yet? Register   Sign In
Counting a values in a column
#2

[eluser]gRoberts[/eluser]
Try using "sum" instead.

i.e.

Code:
$this->db->select('make')->select('model, SUM(Amount) AS total')->group_by('model')

You would need to change `Amount` to the column that contains the `Amount` value in your example above but what your doing at the moment is "Counting" how many rows there are, rather than adding each of the values together.

`Sum` takes the value of each of the rows caught in the "group_by" and adds them together.


Messages In This Thread
Counting a values in a column - by El Forum - 05-13-2012, 10:23 AM
Counting a values in a column - by El Forum - 05-14-2012, 02:50 AM
Counting a values in a column - by El Forum - 05-14-2012, 03:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB