SUM() Function

The SUM() function is designed to calculate the total of a numeric column across multiple rows. This function is particularly useful in financial contexts, where organizations often need to know total revenues, expenses, or salaries. The syntax for using SUM() is straightforward: SELECT SUM(column_name) FROM table_name WHERE condition;. For example, if you want to find the total salary paid to all employees in a specific department, you might use: SELECT SUM(salary) FROM employees WHERE department_id = 10;. In this case, SUM() will aggregate the salaries of only those employees whose department ID matches 10. This function ignores NULL values, ensuring that only valid entries contribute to the total. It can also be combined with GROUP BY to calculate totals for various categories, such as total sales per product line.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *