w3resource

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 Expression: Aggregate Function: Get the total salaries payable to employees.

Relational Algebra Tree:

Relational Algebra Tree: Aggregate Function: Get the total salaries payable to employees.

Pictorial Presentation of the above query

Pictorial: Query to get the total salaries payable to employees.

 

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?



Follow us on Facebook and Twitter for latest update.