SQL SUM() Function - The Coding Shala
Home >> Learn SQL >> SQL SUM() function
The following 'emp' table is used for the examples -
The following SQL query will return the total salary of employees who are from the same city using the SQL SUM() -
SQL SUM() Function
The SQL SUM() function returns the total sum of a numeric column.
SQL SUM() Syntax
The basic syntax of SQL SUM() is as follows -
SELECT SUM(column_name) FROM table_name WHERE condition;
The following 'emp' table is used for the examples -
emp_id emp_name city dept_no salary 1 Akshay Pune 101 50000 3 Nikhil Pune 101 51000 5 Mohit Delhi 103 40000 6 Shubham Surat 105 42000 7 Akash Mumbai 106 45000
SQL SUM() Example
The following SQL query will return the total salary of all the employees using the SQL SUM() Function -
SQL >> select sum(salary) as 'Total Salary' from emp; Output >> Total Salary 228000
The following SQL query will return the total salary of employees who are from the same city using the SQL SUM() -
SQL >> select city, sum(salary) as 'Total Salary' from emp group by city; Output >> city Total Salary Delhi 40000 Mumbai 45000 Pune 101000 Surat 42000
Other Posts You May Like
Comments
Post a Comment