同一选择查询中的Hive查询条件语句

问题描述 投票:1回答:1

是否有一种方法可以使单个配置单元查询进行if-else设置。

在下面的我的数据中,我要确保如果模型为空或具有'-',则在“最终”列中填充“设备”,否则应在“模型”中填充

My data is something like this 

Device  Model 
iPhone  6SPlus  
Samsung -     
Output I want is 
Device  Model   Final
iPhone  6SPlus  6SPlus
Samsung -      Samsung

I am trying a case statement like this but this isn't working.
CASE
       select Device,Model,length(Model) <3 then Device as Final
       else select Device,Model,Model as Final
END

有人可以在这里帮忙吗?

hive case hql hiveql
1个回答
0
投票

阅读有关CASE operator syntax

select device, model, 
       case when length(model) <3 then Device else model end as Final
  from my_table;
© www.soinside.com 2019 - 2024. All rights reserved.