Bird
0
0

You wrote this dbt model in the intermediate layer:

medium📝 Debug Q6 of 15
dbt - Project Organization
You wrote this dbt model in the intermediate layer:
SELECT customer_id, order_date, COUNT(order_id) AS order_count FROM {{ ref('stg_orders') }}

What is the error in this code?
AMissing GROUP BY clause for aggregation
BIncorrect use of ref() function
CCOUNT() cannot be used in intermediate layer
DMissing WHERE clause to filter data
Step-by-Step Solution
Solution:
  1. Step 1: Identify aggregation usage

    The query uses COUNT(order_id), which is an aggregate function.
  2. Step 2: Check for GROUP BY clause

    Since non-aggregated columns customer_id and order_date are selected, a GROUP BY is required but missing.
  3. Final Answer:

    Missing GROUP BY clause for aggregation -> Option A
  4. Quick Check:

    Aggregate functions need GROUP BY for non-aggregated columns [OK]
Quick Trick: Use GROUP BY with aggregates and other columns [OK]
Common Mistakes:
MISTAKES
  • Forgetting GROUP BY with aggregates
  • Thinking ref() usage is wrong here
  • Assuming WHERE is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes