I am using Databricks SQL, and want to understand if I can make my code lighter:
JavaScript
x
8
1
Select
2
case when (
3
age_18__24 is null AND
4
age_25__34 is null AND
5
age_35__44 is null AND
6
age_45_or_more is null
7
) then 1 else 0 end as flag1
8
Instead of writing each line, is there a cool way to state that all of these columns starting with “age_” need to be null in 1 or 2 lines of code?
Advertisement
Answer
If each bin is a column then you probably are going to have to spell it out, but you could use coalesce:
JavaScript
1
6
1
select
2
case when
3
coalesce(age_18__24, age_25__34, age_35__44, age_45_or_more) is null
4
then 1 else 0
5
end as flag1
6