我有一张表格,MyData
格式如下:
|id|theme_id|priority_id|value|
Run Code Online (Sandbox Code Playgroud)
我正在尝试为所有行获得以下结果:
theme_id | priority_id | total | sum
------------------------------------
1 | 1 | 3 | 5
1 | 2 | 5 | 12
1 | 3 | 1 | 3
2 | 1 | 2 | 6
Run Code Online (Sandbox Code Playgroud)
我们的想法是组中的所有行通过theme_id
和priority_id
再总结的数值为分组,以及,以获取进入那笔总行。
当我尝试以下操作时,我得到一个与 sum 列相等的 total 列:
|id|theme_id|priority_id|value|
Run Code Online (Sandbox Code Playgroud)
我也试过:
SELECT theme_id, priority_id, sum(value) AS values, count(id) as total
FROM MyData
GROUP BY theme_id, priority_id
Run Code Online (Sandbox Code Playgroud)
以上两个都给了我相同的输出:
theme_id | priority_id | total | sum
------------------------------------
1 | 1 …
Run Code Online (Sandbox Code Playgroud)