To retrieve sum of the records of a numeric column from the existing created table. Then we can use a ' SELECT ' statement with the SUM() function.
The basic syntax of the SELECT statement with SUM() function is given below –
SELECT SUM(numeric_column_name) FROM table_name;
SELECT SUM(salary) FROM employees;
Here it will retrieve a sum of salary in the record from the employees' table.
We can use whereas Condition / Clause in a select statement such as WHERE, GROUP BY, HAVING, ORDER BY, ETC.
With condition (USING WHERE)
The basic syntax of the ‘ SELECT ‘ statement with SUM() function using WHERE condition is given below –
SELECT SUM(numeric_column_name) FROM table_name WHERE [CONDITION] ;
SELECT SUM(salary) FROM employees WHERE employee_id>150;
Here it will retrieve a sum of salary from the employee table whose employee_id is greater than 150.
Best learning portal that provides you great learning experience of various technologies with modern compilation tools and technique
Don't hesitate to give us a call or send us a contact form message