Employees Above Department Average
Find employees whose salary is higher than the average salary of their department. Return columns: salary, last_name, first_name, department_id.
Practice nested queries and compare values against calculated result sets. These 2 interactive challenges use real schemas and instant query validation.
Find employees whose salary is higher than the average salary of their department. Return columns: salary, last_name, first_name, department_id.
Find orders whose total amount is greater than the average order value. Return columns: id, customer_id, total_amount. Order results by: total_amount DESC.
Concept guide
A SQL subquery is a query nested inside another statement. It can return a scalar value, a list of values, or a derived table used by the outer query.
EXISTS is a natural choice when you only need to know whether a matching row exists. Always consider NULL behavior when using IN or NOT IN.
Not automatically. Modern optimizers can transform both forms. Choose the clearest correct query, then inspect the execution plan for performance-sensitive work.