函数来替换HIVE SQL中的NULL或Empty值



我有一个表,其中两列是"customer_name"one_answers"customer_name_modified"。当"customer_name_modified"为空时,我是否可以在查询中编写一个函数,用"customer_name"填充"customer_name_modified"值?

您可以使用case表达式:

select
customer_name,
case when customer_name_modified is null or customer_name_modified = '' 
then customer_name 
else customer_name_modified 
end customer_name_modified 
from mytable

如果您正在寻找update语句:

update mytable
set customer_name_modified = customer_name
where customer_name_modified is null or customer_name_modified = '' 

最新更新