Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Sql-functions MySQL Addition

Related Tutorials


 
 

Share on Google+Share on Google+

MySQL Addition

Advertisement
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         |
+-------------+

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 17, 2009

Related Tutorials

Discuss: MySQL Addition  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com