Q1 Find employees earning more than the company average salary.
Here, we want to find employees whose salary is higher than the average salary of all employees.
The query starts by selecting all columns from the employees table.
Then, in the WHERE clause, we use a subquery:
SELECT AVG(salary) FROM employees
SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

This calculates the average salary across all 15 employees.
The outer query then compares each employee’s salary against that average.
Only employees whose salary is greater than the average are returned.
In our example, the average salary is 110,400.
That’s why the query returns 8 employees, including James Anderson with 125,000, Emily Davis with 115,000, Robert Moore with 120,000, and Barbara Harris with 130,000.
This is a great example of using a subquery to calculate a value first, and then use that value to filter the main query.