Bird
0
0

Which advanced pattern best helps you write this cleanly and efficiently?

hard🚀 Application Q15 of 15
dbt - Advanced Patterns
You want to create a dbt model that calculates the average order amount per customer but only for customers with more than 5 orders. Which advanced pattern best helps you write this cleanly and efficiently?
ACalculate average without filtering orders count
BWrite a single SELECT with multiple JOINs without CTEs
CUse multiple separate models without referencing each other
DUse nested CTEs: one to count orders per customer, another to filter, then calculate average
Step-by-Step Solution
Solution:
  1. Step 1: Understand the problem requirements

    You need to filter customers by order count > 5, then calculate average order amount.
  2. Step 2: Identify the best advanced pattern

    Using nested CTEs breaks the problem into steps: count orders, filter customers, then compute average, making code clear and maintainable.
  3. Final Answer:

    Use nested CTEs: one to count orders per customer, another to filter, then calculate average -> Option D
  4. Quick Check:

    Break complex tasks into steps with CTEs = A [OK]
Quick Trick: Use nested CTEs to split filtering and aggregation [OK]
Common Mistakes:
MISTAKES
  • Trying to do all in one complex query
  • Not filtering customers before averaging
  • Avoiding model references and CTEs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes