一尘不染

MySQL Group By和其他列的总和

mysql

我有2列,像这样:

+----------+--------+
|   word   | amount |
+----------+--------+
| dog      |      1 |
| dog      |      5 |
| elephant |      2 |
+----------+--------+

我想对金额求和,以获得结果

+----------+--------+
| dog      |      6 |
| elephant |      2 |
+----------+--------+

到目前为止,我已经尝试过(但失败了)的是:

SELECT word, SUM(amount) FROM `Data` Group By 'word'

阅读 447

收藏
2020-05-17

共1个答案

一尘不染

删除中的单引号WORD。它使列名转换为字符串。

SELECT word, SUM(amount) 
FROM Data 
Group By word
2020-05-17