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

1 Answer

1 votes
1 votes

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

Related questions

2 votes
2 votes
1 answer
2
Subhrangsu asked Jun 18, 2022
447 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 votes
1 votes
1 answer
3
Shubhanshu asked Dec 24, 2018
1,307 views
According to me it should be – “Retrieve the names of all students with a lower rank, than all students with age < 18 ”