0
0
dbtdata~10 mins

if/else logic in models in dbt - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new column status that shows 'active' if is_active is true, otherwise 'inactive'.

dbt
select user_id, case when is_active = [1] then 'active' else 'inactive' end as status from users
Drag options to blanks, or click blank then click option'
A'true'
Bfalse
C1
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around true like 'true' makes it a string, not a boolean.
Using false instead of true reverses the logic.
2fill in blank
medium

Complete the code to assign category as 'high' if score is greater than 80, else 'low'.

dbt
select user_id, case when score [1] 80 then 'high' else 'low' end as category from scores
Drag options to blanks, or click blank then click option'
A<=
B=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' checks for exact equality, not greater than.
Using '<=' or '<' reverses the intended logic.
3fill in blank
hard

Fix the error in the code to correctly assign risk_level based on age: 'senior' if age >= 65, else 'adult'.

dbt
select user_id, case when age [1] 65 then 'senior' else 'adult' end as risk_level from demographics
Drag options to blanks, or click blank then click option'
A>=
B!=
C=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' assigns 'senior' to younger ages incorrectly.
Using '=' only matches exactly 65, missing older ages.
4fill in blank
hard

Fill both blanks to create a column discount that is 0.2 if purchase_amount is greater than 100, else 0.

dbt
select customer_id, case when purchase_amount [1] 100 then [2] else 0 end as discount from sales
Drag options to blanks, or click blank then click option'
A>
B<
C0.2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' reverses the condition.
Using 1 instead of 0.2 assigns wrong discount.
5fill in blank
hard

Fill all three blanks to create a column grade that is 'A' if score >= 90, 'B' if score >= 80, else 'C'.

dbt
select student_id, case when score [1] 90 then 'A' when score [2] 80 then 'B' else [3] end as grade from exams
Drag options to blanks, or click blank then click option'
A>=
B>
C'C'
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' excludes boundary scores like 90 or 80.
Not quoting 'C' makes it invalid as a string.