In codeiginter – is it possible to aggregate totals from a result in mySQL using Active record?
My table:
+-----------------+---------------+----------+
| transaction_ID | category_ID | amount |
+-----------------+---------------+----------+
| 1 | 2 | 5.0 |
+-----------------+---------------+----------+
| 2 | 1 | 6.0 |
+-----------------+---------------+----------+
| 3 | 2 | 4.1 |
+-----------------+---------------+----------+
| 4 | 3 | 1.2 |
+-----------------+---------------+----------+
| 5 | 1 | 7.0 |
+-----------------+---------------+----------+
What I’d like to achieve:
+---------------+----------------+
| category_ID | total_amount |
+---------------+----------------+
| 1 | 13.0 |
+---------------+----------------+
| 2 | 9.1 |
+---------------+----------------+
| 3 | 1.2 |
+---------------+----------------+
Try this,