同一 select 查询中的 Hive 查询条件语句
Hive query conditional statement in same select query
有没有办法在一个单独的配置单元查询中进行 if-else 类型的设置。
在我下面的数据中,我想确保如果 Model 为空或带有“-”,我会用 Device 填充 Final 列,否则它应该填充 Model
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
有人可以帮忙吗?
select device, model,
case when length(model) <3 then Device else model end as Final
from my_table;
有没有办法在一个单独的配置单元查询中进行 if-else 类型的设置。
在我下面的数据中,我想确保如果 Model 为空或带有“-”,我会用 Device 填充 Final 列,否则它应该填充 Model
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
有人可以帮忙吗?
select device, model,
case when length(model) <3 then Device else model end as Final
from my_table;