其他列的MySql Group By和Sum总值

时间:2013-02-24 05:08:22

标签: mysql sql

我有两列像这样

Image of database

我希望结果是狗6和大象2.我到目前为止所做的(并且失败了)是

  

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

5 个答案:

答案 0 :(得分:56)

删除WORD周围的单引号。它会导致列名称转换为字符串。

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

答案 1 :(得分:12)

它应该是grave accent符号而不是single quote

SELECT word, SUM( amount )
FROM Data
GROUP BY `word`;

<强> 输出:

word     SUM(amount)
dog           6
Elephant      2

enter image description here

答案 2 :(得分:2)

SELECT word, SUM(amount) FROM Data Group By word;

答案 3 :(得分:1)

尝试这种非常规方法。

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

答案 4 :(得分:0)

SELECT column_name1, SUM(column_name2) 
FROM table_name 
GROUP BY column_name1