Bird
0
0

What is wrong with this dbt model SQL?

medium📝 Debug Q7 of 15
dbt - Advanced Patterns
What is wrong with this dbt model SQL?
WITH data AS (
  SELECT user_id, COUNT(*) AS order_count FROM orders GROUP BY user_id
)
SELECT user_id, order_count FROM data WHERE order_count > '5'
AComparing integer order_count to string '5' causes type mismatch
BMissing alias for COUNT(*)
CGROUP BY should include order_count
DCTE cannot be named 'data'
Step-by-Step Solution
Solution:
  1. Step 1: Check the WHERE clause condition

    order_count is numeric but compared to string '5'.
  2. Step 2: Understand type comparison rules

    Comparing integer to string can cause errors or unexpected results.
  3. Final Answer:

    Comparing integer order_count to string '5' causes type mismatch -> Option A
  4. Quick Check:

    Numeric vs string comparison causes errors [OK]
Quick Trick: Compare numbers to numbers, not strings [OK]
Common Mistakes:
MISTAKES
  • Ignoring data type mismatches
  • Thinking alias is missing
  • Believing GROUP BY needs order_count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes