w3resource
SQL exercises

SQL Subquery Exercises: Find out the names of all employees whose salary is greater than 50% of their department’s total salary bill

SQL SUBQUERY: Exercise-31 with Solution

Write a query which is looking for the names of all employees whose salary is greater than 50% of their department’s total salary bill.

Sample table: employees


Sample Solution:

SELECT e1.first_name, e1.last_name 
FROM employees e1 
WHERE salary > 
( SELECT (SUM(salary))*.5 
FROM employees e2 
WHERE e1.department_id=e2.department_id);

Sample Output:

first_name	last_name
Kimberely	Grant
Jennifer	Whalen
Michael		Hartstein
Susan		Mavris
Hermann		Baer
Shelley		Higgins

Practice Online


Query Visualization:

Duration:

Query visualization of Find out the names of all employees whose salary is greater than 50% of their department’s total salary bill - Duration

Rows:

Query visualization of Find out the names of all employees whose salary is greater than 50% of their department’s total salary bill - Rows

Cost:

Query visualization of Find out the names of all employees whose salary is greater than 50% of their department’s total salary bill - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a query to find out which employees have a manager who works for a department based in the US.
Next: Write a query to get the details of employees who are managers.

What is the difficulty level of this exercise?



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