Home > Database > Mysql Tutorial > How to Group and Sum Values in MySQL Using GROUP BY?

How to Group and Sum Values in MySQL Using GROUP BY?

Barbara Streisand
Release: 2025-01-01 08:19:10
Original
594 people have browsed it

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
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template