Bird
0
0

Identify the error in this dbt model SQL snippet:

medium📝 Debug Q6 of 15
dbt - Advanced Patterns
Identify the error in this dbt model SQL snippet:
WITH recent_orders AS (
  SELECT * FROM orders WHERE order_date > '2023-01-01'
),
summary AS (
  SELECT customer_id, SUM(amount) AS total FROM recent_orders
)
SELECT * FROM summary
AIncorrect date format in WHERE clause
BMissing GROUP BY clause in summary CTE
CCTE names cannot be reused
DSELECT * is not allowed in dbt models
Step-by-Step Solution
Solution:
  1. Step 1: Review aggregation in summary CTE

    SUM(amount) is used with customer_id but no GROUP BY is present.
  2. Step 2: Understand SQL aggregation rules

    When aggregating with other columns, GROUP BY those columns is required.
  3. Final Answer:

    Missing GROUP BY clause in summary CTE -> Option B
  4. Quick Check:

    Aggregation needs GROUP BY [OK]
Quick Trick: Always add GROUP BY when aggregating with other columns [OK]
Common Mistakes:
MISTAKES
  • Ignoring missing GROUP BY errors
  • Thinking date format is wrong
  • Believing SELECT * is disallowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes