w3resource
MySQL exercises

MySQL Aggregate Functions and Group by- Exercises, Practice, Solution

Aggregate Functions and Group by [14 exercises with solution]

1. Write a query to list the number of jobs available in the employees table. Go to the editor

Sample table: employees


Click me to see the solution

2. Write a query to get the total salaries payable to employees. Go to the editor

Sample table: employees


Click me to see the solution

3. Write a query to get the minimum salary from employees table. Go to the editor

Sample table: employees


Click me to see the solution

4. Write a query to get the maximum salary of an employee working as a Programmer. Go to the editor

Sample table: employees


Click me to see the solution

5. Write a query to get the average salary and number of employees working the department 90. Go to the editor

Sample table: employees


Click me to see the solution

6. Write a query to get the highest, lowest, sum, and average salary of all employees. Go to the editor

Sample table: employees


Click me to see the solution

7. Write a query to get the number of employees with the same job. Go to the editor

Sample table: employees


Click me to see the solution

8. Write a query to get the difference between the highest and lowest salaries. Go to the editor

Sample table: employees


Click me to see the solution

9. Write a query to find the manager ID and the salary of the lowest-paid employee for that manager. Go to the editor

Sample table: employees


Click me to see the solution

10. Write a query to get the department ID and the total salary payable in each department. Go to the editor

Sample table: employees


Click me to see the solution

11. Write a query to get the average salary for each job ID excluding programmer. Go to the editor

Sample table: employees


Click me to see the solution

12. Write a query to get the total salary, maximum, minimum, average salary of employees (job ID wise), for department ID 90 only. Go to the editor

Sample table: employees


Click me to see the solution

13. Write a query to get the job ID and maximum salary of the employees where maximum salary is greater than or equal to $4000. Go to the editor

Sample table: employees


Click me to see the solution

14. Write a query to get the average salary for all departments employing more than 10 employees. Go to the editor

Sample table: employees


Click me to see the solution

... More

Structure of 'hr' database:

hr database

MySQL Code Editor:

Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.