Bird
0
0

What will be the result of this dbt model SQL?

medium📝 Predict Output Q5 of 15
dbt - Advanced Patterns
What will be the result of this dbt model SQL?
WITH sales AS (
  SELECT product_id, SUM(amount) AS total_sales FROM orders GROUP BY product_id
),
top_sales AS (
  SELECT * FROM sales WHERE total_sales > 1000
)
SELECT COUNT(*) AS top_product_count FROM top_sales
AError due to missing GROUP BY in top_sales
BSum of all sales amounts
CList of all products sold
DCount of products with sales over 1000
Step-by-Step Solution
Solution:
  1. Step 1: Understand the sales aggregation

    The first CTE sums sales per product_id.
  2. Step 2: Filter products with sales > 1000

    The second CTE selects only products with total_sales greater than 1000.
  3. Step 3: Count filtered products

    The final SELECT counts how many products meet the criteria.
  4. Final Answer:

    Count of products with sales over 1000 -> Option D
  5. Quick Check:

    top_product_count = count of products with sales > 1000 [OK]
Quick Trick: Filter aggregated data before counting for specific conditions [OK]
Common Mistakes:
MISTAKES
  • Confusing sum with count
  • Expecting a list instead of a count
  • Thinking GROUP BY needed in filtered CTE

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes