w3resource
SQL exercises

SQL SORTING and FILTERING on HR Database: Display the average salary of employees for each department who gets a commission percentage

SQL SORTING and FILTERING on HR Database: Exercise-29 with Solution

29. Write a query in SQL to display the average salary of employees for each department who gets a commission percentage.

Sample table: employees


Sample Solution:

SELECT department_id, AVG(salary) 
	FROM employees 
		WHERE commission_pct IS NOT NULL 
			GROUP BY department_id;

Sample Output:

 department_id |          avg
---------------+------------------------
            90 |     19333.333333333333
            20 |  9500.0000000000000000
           100 |  8600.0000000000000000
            40 |  6500.0000000000000000
           110 | 10150.0000000000000000
            80 |  8955.8823529411764706
            70 | 10000.0000000000000000
            50 |  3475.5555555555555556
            60 |  5760.0000000000000000
            30 |  4150.0000000000000000
            10 |  4400.0000000000000000
             0 |  7000.0000000000000000
(12 rows)

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display the average salary of employees for each department who gets a commission percentage - Duration

Rows:

Query visualization of Display the average salary of employees for each department who gets a commission percentage - Rows

Cost:

Query visualization of Display the average salary of employees for each department who gets a commission percentage - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to display the first and last name and date of joining of the employees who is either Sales Representative or Sales Man.
Next: Write a query in SQL to display those departments where any manager is managing 4 or more employees.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming