1,789 views
0 0 votes
Write SQL command to find DepartmentID, EmployeeName from Employee table whose average salary is above 20000.

1 Answer

1 1 vote

This query will select the DepartmentID and EmployeeName columns
from the Employee table
and return only the rows where the average salary of all employees
in the table is above $20000$ :-


//SQL CODE:-
SELECT DepartmentID, EmployeeName
FROM Employee
WHERE (SELECT AVG(Salary) FROM Employee) > 20000;

 

This query will select the DepartmentID and EmployeeName columns from the Employee table, and return all rows where the average salary for the department is above 20000. The subquery in the WHERE clause calculates the average salary for each department by selecting the Salary column from the Employee table, grouped by DepartmentID. The outer query then filters the results to include only rows where the average salary is above $20000$ :-

 

//SQL CODE:-
SELECT DepartmentID, EmployeeName
FROM Employee AS e
WHERE (SELECT AVG(Salary) FROM Employee WHERE DepartmentID = e.DepartmentID) > 20000

 

edited by
Position:
Show:

Related questions

1 1 vote
1 answers 1 answer
1.2k
1.2k views
tishhaagrawal asked Dec 16, 2023
1,174 views
My doubt here is, if NOT EXISTS gets an empty set as the input then every tuple of the table in the outer query must satisfy the condition. Am I right?For example, in the...
2 2 votes
1 1 answer
835
835 views
Subhrangsu asked Jun 18, 2022
835 views
Write SQL query to show all employees hired on June 4,1984 (non-default format)emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)
1 1 vote
1 1 answer
2.5k
2.5k views
Shubhanshu asked Dec 24, 2018
2,524 views
According to me it should be – “Retrieve the names of all students with a lower rank, than all students with age < 18 ”
0 0 votes
0 0 answers
1.2k
1.2k views
Ashwani Yadav asked Dec 20, 2018
1,157 views
Suppose there are two tuples in Animals relation with different IDs but of same type and in Adoption table there is a tuple with an ID that matches with the ID of first ...