Ugleh Ugleh - 3 months ago 17
SQL Question

MySql Group By and Sum total value of other column

I have 2 columns like so

Image of database

I want the result to be dog 6, and Elephant 2. What I have made so far (and failed) is this


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

Answer

Remove the single quote around the WORD. It causes the column name to be converted as string.

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