简体   繁体   中英

DECODE function in Hive in WHERE Clause

Can someone please help to convert below query of Oracle in Hive ?

select * 
  from tbl_my_details a 
 where decode(a.my_code,'ALL','99','01','01','02','02','03','03','04','04','06','06',
                 'Other') = a.my_content

You may use case..when structure as follows :

select *
  from tbl_my_details a
 where (
        case 
        when a.my_code = 'ALL' then '99'
        when a.my_code in ('01','02','03','04','06') then a.my_code
        else 'Other'
        end 
       ) = a.my_content;

In either database, simple boolean logic is preferable:

select * 
from tbl_my_details a 
where (a.my_code in ('01', '02', '03', '04', '06') and a.my_content = a.my_code) or
      (a.my_code = 'ALL' and a.my_content = '99') or
      (a.my_code not in ('01', '02', '03', '04', '06', 'ALL') and a.my_content = 'Other')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM