Complete the code to select the average salary from the employees table.
SELECT (SELECT [1](salary) FROM employees) AS avg_salary;The AVG function calculates the average value of a column. Here, it returns the average salary.
Complete the code to find employees whose salary is greater than the average salary.
SELECT name FROM employees WHERE salary > (SELECT [1](salary) FROM employees);The subquery calculates the average salary using AVG. The main query selects employees earning more than this average.
Fix the error in the scalar subquery to correctly get the maximum salary.
SELECT name, salary FROM employees WHERE salary = (SELECT [1](salary) FROM employees);Use MAX( to form the correct aggregate function syntax MAX(salary) in the scalar subquery.
Fill both blanks to select employees whose salary is between the minimum and maximum salaries.
SELECT name FROM employees WHERE salary BETWEEN (SELECT [1](salary) FROM employees) AND (SELECT [2](salary) FROM employees);
The MIN function gets the lowest salary, and MAX gets the highest. Using BETWEEN with these selects salaries in that range.
Fill all three blanks to select employees whose salary is greater than the average salary and less than the maximum salary.
SELECT name FROM employees WHERE salary > (SELECT [1](salary) FROM employees) AND salary < (SELECT [2](salary) FROM employees) ORDER BY [3];
The query compares salary to the average and maximum using AVG and MAX. It orders results by the salary column.