我有两列像这样
我希望结果是狗6和大象2.我到目前为止所做的(并且失败了)是
SELECT word,SUM(amount)FROM
Data
Group By'word'
答案 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
答案 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