Home Sql Sql-functions MySQL Addition



MySQL Addition
Posted on: June 17, 2009 at 12:00 AM
MySQL Addition returns you the sum value of a specific column for a group in a table.

MySQL Addition

     

MySQL Addition returns you the sum value of a specific column for a group in a table. The Aggregate function sum() is used to perform the addition in SQL Query. We can make use of Aggregate function with group by and order by clause.

Syntax:

SUM([DISTINCT] column_name):

Returns the sum of the values of the column column_name. If there are no rows then SUM() returns NULL. The DISTINCT keyword can be used to sum only the distinct values of the column.

Understand with Example

The Tutorial illustrates an example of 'MySQL Addition'. To understand the example we have a table employee in the database. The select order by query is used to sort the records by specific column. In this example we sort the records of name and salary on the basis of salary column from table 'employee'.

Query

 

select name, salary from employee order by salary;

 

Output

 

+--------+--------+
| name   | salary |
+--------+--------+
| Kamal  | 101    |
| Ajay   | 105    |
| Nitin  | 110    |
| Rajiv  | 120    |
| Vinay  | 130    |
| Sachin | 150    |
| Karan  | 160    |
+--------+--------+

In this example, the sum() function is used to calculate sum of salary of all employees in a table 'employee'.

Query

 

 select sum(salary) from employee;

 

Output

 

+-------------+
| sum(salary) |
+-------------+
| 876         |
+-------------+

 

Related Tags for MySQL Addition:
sqlcqueryormformfunctionfuniosedsumaggregateforuncaddtoeitusepeinrmmddadditionadfuncssuatisgressthgagatono


More Tutorials from this section

Ask Questions?    Discuss: MySQL Addition  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.