Thursday, July 14, 2016

SUM( )

SQL SUM function use for sum various column .  This return by a  select statement.For understanding SQL SUM  following  tbl_User table. In this we have following record.


UserId
Salary
Role
1
1000
U
2
1100
U
3
1300
U
4
1000
R
5
900
A

Example:

Sum values from the salary column.

SELECT 
Sum(Salary
from tbl_User ;


Query output:

Salary
5300


 If you want know this month combined total salary which is above then 1000.

SELECT
Sum(Salary) As total_salary
from tbl_User
where Salary>1000;


Sum unique salary values from the salary column.

SELECT
Sum(Distinct Salary) As total_salary
from tbl_User ;

No comments:

Post a Comment