hive-find 2 characters anywhere in the string/行-rlike

qzwqbdag  于 2021-06-25  发布在  Hive
关注(0)|答案(2)|浏览(408)

如何仅获取分配给“usa\u rbb\u wa\u bu”的“\u wa”数据?但是,我看到的列中有行包含∗wa和∗sa(usa\u ca\u sawant)
我用过,

select....
                         'USA_RBB_WA_BU' AS State ,
                         District 
                         from TABLE where district like '%_WA%'

                        select   ...
                         'USA_RBB_NSW_BU' AS State ,
                         District 
                         from TABLE where district like '%_SA%'

然而,我最终得到了下面的数据输出表


**state                  district**

USA_RBB_NSW_BU          USA_CA_SAWANT
USA_RBB_WA_BU           USA_CA_SAWANT
USA_RBB_NSW_BU          USA_CA_SAWANT
USA_RBB_WA_BU           USA_CA_SAWANT

我试过了

select....
                         'USA_RBB_WA_BU' AS State ,
                         District 
                         from TABLE where district like '_WA%'

                         output was  was 0 results in hive
wxclj1h5

wxclj1h51#

我猜你是想逃跑 _ 在这里。试试下面-

SELECT <FIELD_LIST>
       'USA_RBB_WA_BU' AS State ,
       District 
FROM TABLE
WHERE district RLIKE '.*_WA%'
hrirmatl

hrirmatl2#

where district rlike '_WA' 将正常工作(如果字符串包含\u wa,则返回true)
如果您希望字符串包含前后的内容 _WA ,添加 .+ (任意字符一次或多次):

where district rlike '.+_WA.+'

相关问题