How to use sum in MYSQL
How to use sum in MYSQL
563
27-Jul-2023
Aryan Kumar
28-Jul-2023The
SUM()function in MySQL is used to calculate the sum of a set of values. It can be used with any set of numeric values, such as integers, floats, doubles, and decimals.The syntax for the
SUM()function is as follows:SQL
The
column_nameparameter is the name of the column that you want to sum. For example, the following SQL statement will calculate the sum of all product prices in theproductstable:SQL
This will return a single value, which is the sum of all product prices in the
productstable.Here is an example of how to use the
SUM()function in MySQL:SQL
This will return the following result:
As you can see, the
SUM()function has calculated the sum of all product prices in theproductstable, which is 1500.Here are some additional things to keep in mind when using the
SUM()function:SUM()function ignores NULL values.DISTINCTkeyword to calculate the sum of distinct values in a column.GROUP BYclause to calculate the sum of values in a group.