代码之家  ›  专栏  ›  技术社区  ›  titutubs

有没有一种更有效的方法来为Databricks SQL中的bin值编写代码?

  •  0
  • titutubs  · 技术社区  · 3 年前

    我正在使用Databricks SQL,并想了解我是否可以使代码更轻量级:

       Select
    case when (
            age_18__24 is null AND
            age_25__34 is null AND
            age_35__44 is null AND
            age_45_or_more is null
          ) then 1 else 0 end as flag1...
    

    是否有一种很酷的方式来声明所有以“age\uu1”开头的列在1行或2行代码中都需要为null,而不是编写每一行?

    1 回复  |  直到 3 年前
        1
  •  2
  •   lesk_s    3 年前

    如果每个箱子都是一列,那么你可能需要把它拼出来,但你可以使用 coalesce :

    select
      case when 
        coalesce(age_18__24, age_25__34, age_35__44, age_45_or_more) is null 
        then 1 else 0
      end as flag1