Hive中的嵌套案例声明

tzh*_*g94 2 sql hadoop sas hiveql

有谁知道为什么此代码不起作用?

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
Run Code Online (Sandbox Code Playgroud)

还是有一个更简单的方法来做到这一点?我正在proc sql语句中编写此代码,并将其推送到Hadoop(因此它必须与HiveQL兼容)。

小智 5

使用AND或OR子句将嵌套的Case语句合并为一个case语句。