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