sql - Hive 中的嵌套案例语句

标签 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

或者有更简单的方法吗?我在 proc sql 语句中编写它并将其推送到 Hadoop(因此它需要与 HiveQL 兼容)。

最佳答案

使用 AND 或 OR 子句将嵌套的 Case 语句组合成一个 case 语句。这将起作用。

关于sql - Hive 中的嵌套案例语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33746185/

相关文章:

MySQL分组显示零记录

sql - MySQL 在特定时间间隔查询行

hadoop - 如何将位于 HDFS 上的类型安全配置文件添加到 spark-submit(集群模式)?

sas - 从 proc sql 写入文件

sas teradata 快速加载问题

sql - PIVOT 不起作用 ')' 附近语法错误

mysql - 如何计算每个全名的平均值并重复该值?

java - 需要删除 HDFS 中的part-m-0000* 文件

sorting - 我可以为reducer中的记录分配序列号吗

sas - 启用 SAS 读取汉字