Home >Database >Mysql Tutorial >How to Group and Sum Values in MySQL Using GROUP BY?
MySQL Query to Group By and Sum Total Values
This query can be used to group and sum values in two columns of a table. In this case, the table has columns word and amount. The query groups the rows by the word column and sums the values in the amount column, providing a result that includes the total amount for each unique word.
The query that achieves this:
SELECT word, SUM(amount) FROM Data GROUP BY word
The query attempts to remove the single quote around the word in the GROUP BY clause. The single quote causes the column name to be converted to a string, preventing the correct grouping.
The above is the detailed content of How to Group and Sum Values in MySQL Using GROUP BY?. For more information, please follow other related articles on the PHP Chinese website!