Bird
0
0

Given this dbt model SQL snippet, what will be the output of final_count?

medium📝 Predict Output Q4 of 15
dbt - Advanced Patterns
Given this dbt model SQL snippet, what will be the output of final_count?
WITH filtered_data AS (
  SELECT * FROM users WHERE active = TRUE
),
count_data AS (
  SELECT COUNT(*) AS final_count FROM filtered_data
)
SELECT final_count FROM count_data
AThe number of active users
BThe total number of users
CA list of active users
DAn error due to missing GROUP BY
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the filtering step

    The first CTE filters users where active is TRUE, so only active users remain.
  2. Step 2: Analyze the counting step

    The second CTE counts rows from filtered_data, so it counts active users.
  3. Final Answer:

    The number of active users -> Option A
  4. Quick Check:

    final_count = count of active users [OK]
Quick Trick: CTEs can filter then count data stepwise [OK]
Common Mistakes:
MISTAKES
  • Confusing total users with active users count
  • Expecting a list instead of a count
  • Thinking GROUP BY is required for COUNT(*)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes