mySql  sum() function

the mysql sum function allows you to calculate the sum of a set of values or an expression.

mysql sum() syntax

         select    sum(column_name or expre)    from   table_name;

or

         select    sum(column_name or expre)    from   table_name;

the sum() function ignores the null value in calculation.

the sum() function returns null if there is no matching row.

the distinct operator allows you to calculate distinct values in the set.

This demo database table use in the below sum function example

below is a selection from the "users" table:

useridfirstnamesalarybonus
1sandeep10,0001000
2ankit20,0002000
3ram30,0003000
4vikram12,0002000

mysql sum function example

the following mysql statement calculate the sum of all the "bonus" fields for the "users" table:

               
               select    sum(bonus)    as   bonus_sum      from    users;

output :

bonus_sum
8000