有人知道为什么这段代码不起作用吗?
create table2 as
select
*,
1 as count,
case
when a=1 then
case
when tx="A_L" then "L"
when tx="B_A" then "A"
when tx="C_E" then "E"
when tx in ("E_V","D_M","H_O","I_D") then "Other"
when tx="F_S" then "S"
when tx="G_L" then "L"
end
when b=1 then
case
when tx="A_L" then "L"
when tx="B_A" then "A"
when tx="C_E" then "E"
end
else
case
when tx="A_L" then "L"
when tx="B_A" then "A"
when tx="C_E" then "E"
when tx in ("D_M","E_V","F_S","H_O","I_D") then "Other"
when tx="G_L" then "L"
end
end as tx1
from table1
或者有更简单的方法吗?我在 proc sql 语句中编写它并将其推送到 Hadoop(因此它需要与 HiveQL 兼容)。
最佳答案
使用 AND 或 OR 子句将嵌套的 Case 语句组合成一个 case 语句。这将起作用。
关于sql - Hive 中的嵌套案例语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33746185/