Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从mySQL中的结果聚合总计_Mysql_Codeigniter - Fatal编程技术网

从mySQL中的结果聚合总计

从mySQL中的结果聚合总计,mysql,codeigniter,Mysql,Codeigniter,在codeiginter中-是否可以使用活动记录在mySQL中聚合结果的总计 我的桌子: +-----------------+---------------+----------+ | transaction_ID | category_ID | amount | +-----------------+---------------+----------+ | 1 | 2 | 5.0 | +----------------

在codeiginter中-是否可以使用活动记录在mySQL中聚合结果的总计

我的桌子:

+-----------------+---------------+----------+
|  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    |
+-----------------+---------------+----------+
+---------------+----------------+
|  category_ID  |  total_amount  |
+---------------+----------------+
|       1       |      13.0      |
+---------------+----------------+
|       2       |      9.1       |
+---------------+----------------+
|       3       |      1.2       |
+---------------+----------------+
我想要达到的目标:

+-----------------+---------------+----------+
|  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    |
+-----------------+---------------+----------+
+---------------+----------------+
|  category_ID  |  total_amount  |
+---------------+----------------+
|       1       |      13.0      |
+---------------+----------------+
|       2       |      9.1       |
+---------------+----------------+
|       3       |      1.2       |
+---------------+----------------+
试试这个

SELECT category_ID, SUM(amount) totalAmount
FROM tableName
GROUP BY categoryID