Reorganized title: Calculating the total value of other columns using MySQL's Group By and Sum
P粉908138620
P粉908138620 2023-08-27 19:13:59
0
2
433

I have two columns like this:

Word Amount
dog 1
dog 5
Elephant 2

I want to sum the amounts and get the result

Word Amount
dog 6
Elephant 2

What I have tried (and failed) so far is:

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


P粉908138620
P粉908138620

reply all (2)
P粉165522886

It should beaccentedsymbol instead ofsingle quote:

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

Output:

word SUM(amount) dog 6 Elephant 2

    P粉377412096

    Remove the single quotes aroundWORD. It causes column names to be converted to strings.

    SELECT word, SUM(amount) FROM Data Group By word
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!