# SQL SUM Function

Category : TECH Author : Ankur Rastogi Date : Sun Mar 27 2016 Views : 44

### Overview

SQL SUM() function returns the aggregated summation of all the values for input column name. There are lot of real scenario application uses for SUM function like calculate total population of a state by finding sum of its city wise population. Other use can be to find out the total salary given by company by finding out the sum of all the employee's salary.

Other use case can be suppose in one table you have list of purchased goods than you can use sql sum function to calculate price of all the goods. Later we will see more examples

We also wrote about some of the other sql functions

### Syntax

Syntax for SUM function is

*SELECT SUM(column_name) FROM hostel_list;*

### Examples

Let us understand SUM function better with the help of an example

Consider table hostel_list which contains hostel_list details.

+----+-------------------+-----------+----------+

| id | name | occupancy | capacity |

+----+-------------------+-----------+----------+

| 1 | ASHOK BHAVAN | 2 | 1090 |

| 2 | KAILASH BHAVAN | 2 | 990 |

| 3 | RUDRAKSH BHAVAN | 2 | 990 |

| 4 | KAVERI BHAVAN | 1 | 690 |

| 5 | BHAGIRATHI BHAVAN | 4 | 2140 |

| 6 | NARMADA BHAVAN | 6 | 3240 |

| 7 | GANGA BHAVAN | 1 | 780 |

| 8 | YAMUNA BHAVAN | 8 | 4580 |

+----+-------------------+-----------+----------+

#### SQL SUM Example Case 1:

Let us find the total hostel capacities, SQL query for that will be

**SELECT SUM(capacity) FROM hostel_list;**

+---------------+

| SUM(capacity) |

+---------------+

| 14500 |

+---------------+

#### SQL SUM Example Case 2:

Suppose we want to find out the total number of occupancy college has, than we can find out by using sql query

SELECT SUM(occupancy) FROM hostel_list;

+----------------+

| SUM(occupancy) |

+----------------+

| 26 |

+----------------+

1 row in set (0.01 sec)

### Overview

SQL SUM() function returns the aggregated summation of all the values for input column name. There are lot of real scenario application uses for SUM function like calculate total population of a state by finding sum of its city wise population. Other use can be to find out the total salary given by company by finding out the sum of all the employee's salary.

Other use case can be suppose in one table you have list of purchased goods than you can use sql sum function to calculate price of all the goods. Later we will see more examples

We also wrote about some of the other sql functions

### Syntax

Syntax for SUM function is

*SELECT SUM(column_name) FROM hostel_list;*

### Examples

Let us understand SUM function better with the help of an example

Consider table hostel_list which contains hostel_list details.

+----+-------------------+-----------+----------+

| id | name | occupancy | capacity |

+----+-------------------+-----------+----------+

| 1 | ASHOK BHAVAN | 2 | 1090 |

| 2 | KAILASH BHAVAN | 2 | 990 |

| 3 | RUDRAKSH BHAVAN | 2 | 990 |

| 4 | KAVERI BHAVAN | 1 | 690 |

| 5 | BHAGIRATHI BHAVAN | 4 | 2140 |

| 6 | NARMADA BHAVAN | 6 | 3240 |

| 7 | GANGA BHAVAN | 1 | 780 |

| 8 | YAMUNA BHAVAN | 8 | 4580 |

+----+-------------------+-----------+----------+

#### SQL SUM Example Case 1:

Let us find the total hostel capacities, SQL query for that will be

**SELECT SUM(capacity) FROM hostel_list;**

+---------------+

| SUM(capacity) |

+---------------+

| 14500 |

+---------------+

#### SQL SUM Example Case 2:

Suppose we want to find out the total number of occupancy college has, than we can find out by using sql query

SELECT SUM(occupancy) FROM hostel_list;

+----------------+

| SUM(occupancy) |

+----------------+

| 26 |

+----------------+

1 row in set (0.01 sec)

If you want to add more comments to the article or you see any thing incorrect please write a comment below and we will surely get back to you.