Bird
0
0

You want to calculate the average sales per region and then find regions with average sales above 5000. Which approach using CTEs is best?

hard📝 Application Q8 of 15
SQL - Common Table Expressions (CTEs)
You want to calculate the average sales per region and then find regions with average sales above 5000. Which approach using CTEs is best?
ACalculate average sales directly in main query without CTE
BUse a CTE to calculate average sales per region, then filter in main query
CCreate a temporary table instead of using a CTE
DUse a subquery inside WHERE clause without CTE
Step-by-Step Solution
Solution:
  1. Step 1: Understand the problem

    We need to calculate averages first, then filter regions based on that.
  2. Step 2: Evaluate CTE usage

    Using a CTE to calculate averages makes the query clearer and reusable for filtering.
  3. Final Answer:

    Use a CTE to calculate average sales per region, then filter in main query -> Option B
  4. Quick Check:

    CTEs simplify multi-step calculations and filtering [OK]
Quick Trick: CTEs help break complex queries into clear steps [OK]
Common Mistakes:
  • Skipping CTE and writing complex nested queries
  • Using temporary tables unnecessarily
  • Confusing subqueries with CTE advantages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes