zoukankan      html  css  js  c++  java
  • hive:条件判断函数

    参考hive常用运算

    •If函数: if

    •非空查找函数: COALESCE

    •条件判断函数:CASE

    • If 函数 : if

    语法: if(boolean testCondition, T valueTrue, T valueFalseOrNull)

    返回值: T

    说明:  当条件testCondition为TRUE时,返回valueTrue;否则返回valueFalseOrNull

    举例:

    hive> select if(1=2,100,200) from dual;

    200

    hive> select if(1=1,100,200) from dual;

    100

    • 非空查找函数 : COALESCE

    语法: COALESCE(T v1, T v2, …)

    返回值: T

    说明:  返回参数中的第一个非空值;如果所有值都为NULL,那么返回NULL

    举例:

    hive> select COALESCE(null,'100','50′) from dual;

    100

    条件判断函数: CASE

    语法 : CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END

    返回值 : T

    说明:如果 a 等于 b ,那么返回 c ;如果 a 等于 d ,那么返回 e ;否则返回 f

    举例:

    hive> Select case 100 when 50 then 'tom' when 100 then 'mary' else 'tim' end from dual;

     
    实例:
    insert overwrite table branch_atmzc
    Select canal, XT_OP_TRL, SA_TX_DT,if(dr_cr_cod = '2',-abs(cr_tx_amt),cr_tx_amt) as cr_tx_amt2 from branch_atm
    group by
    canal,XT_OP_TRL , SA_TX_DT,dr_cr_cod,cr_tx_amt;
    insert overwrite table branch_atmzc
    Select canal, XT_OP_TRL, SA_TX_DT,case when (tran_cd  = '1062' or tran_cd = '5069') then '取款' when (tran_cd = '5148' or tran_cd = '1061') then '存款' when (tran_cd ='5069') then '手续费' when (tran_cd ='5076' or tran_cd = '5922' or tran_cd = '3806') then '转账' else '其他' end as tran_cd, sum(cr_tx_amt),sum(counts) from branch_atm
    group by
    canal, XT_OP_TRL , SA_TX_DT,tran_cd ;
    

      

     
  • 相关阅读:
    学习笔记-JMeter 操作 Mysql
    学习笔记-JMeter 关联
    学习笔记-JMeter参数化
    研究 Table DOM对象的属性和方法
    tornado web.py Application类源码剖析
    根据 HTTP header 收集客户端相关信息
    【指针】基于双向链表的list
    【指针】基于单向链表的list(待改进)
    【递归】汉诺塔
    【递归】全排列
  • 原文地址:https://www.cnblogs.com/kxdblog/p/4034243.html
Copyright © 2011-2022 走看看