SUM function in Mysql

By | January 18, 2014

This function used to find the sum of fields in various records

See the example below

Select * from mydoubts_data

————————————-
|id | jobid | name | salary | age|
————————————-
|1 | 121 | vasanthan| 2000 |32 |
|2 | 122 | John | 3000 |28 |
|3 | 123 | Kiran | 3400 |24 |
|4 | 154 | Raju | 2800 |38 |
|5 | 155 | Raju | 2906 |40 |
|6 | 143 | Kiran | 3400 |42 |

select sum(salary) from mydoubts_data

————————–
| SUM(salary) |
————————–
| 17506|
—————————

Select name,sum(salary) from mydoubts_data group by name

——————–
name | salary |
——————–
vasanthan | 2000
| John | 3000
| Kiran | 6800
| Raju | 5706