Bird
0
0

You want to find all customers who placed orders with a total amount greater than the average order amount. Which query correctly uses a subquery to achieve this?

hard📝 Application Q15 of 15
SQL - Subqueries
You want to find all customers who placed orders with a total amount greater than the average order amount. Which query correctly uses a subquery to achieve this?
ASELECT customer_id FROM orders WHERE total_amount > AVG(total_amount);
BSELECT customer_id FROM orders WHERE total_amount > (SELECT AVG(total_amount) FROM orders);
CSELECT customer_id FROM orders WHERE total_amount IN (SELECT AVG(total_amount) FROM orders);
DSELECT customer_id FROM orders WHERE total_amount = (SELECT total_amount FROM orders WHERE total_amount > AVG(total_amount));
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    We want customers with orders greater than the average order amount.
  2. Step 2: Check subquery usage

    SELECT customer_id FROM orders WHERE total_amount > (SELECT AVG(total_amount) FROM orders); correctly uses a subquery to calculate average and compares each order's total_amount to it.
  3. Step 3: Identify errors in other options

    SELECT customer_id FROM orders WHERE total_amount > AVG(total_amount); misuses AVG without subquery; C uses IN incorrectly; D has wrong comparison logic.
  4. Final Answer:

    SELECT customer_id FROM orders WHERE total_amount > (SELECT AVG(total_amount) FROM orders); -> Option B
  5. Quick Check:

    Subquery calculates average, main query compares amounts [OK]
Quick Trick: Use subquery to get average, compare in main query [OK]
Common Mistakes:
MISTAKES
  • Using aggregate functions without subqueries
  • Misusing IN for single value comparisons
  • Comparing with wrong operators or missing parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes