MySQL Aggregate Function Exercises: Get the total salaries payable to employees
MySQL Aggregate Function: Exercise-2 with Solution
Write a query to get the total salaries payable to employees.
Sample table: employees
Code:
-- Calculating the total sum of salaries for all employees
SELECT SUM(salary)
-- Selecting data from the employees table
FROM employees;
Explanation:
- This SQL query calculates the total sum of salaries for all employees in the employees table.
- The SUM() function is an aggregate function that adds up all the values in the specified column (salary in this case).
- This query is useful when you want to find out the total salary expense for all employees in the organization.
Relational Algebra Expression:
Relational Algebra Tree:
Pictorial Presentation of the above query
MySQL Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a query to list the number of jobs available in the employees table.
Next: Write a query to get the minimum salary from employees table.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics