HIVE SQL的WHERE子句不如预期工作。

huangapple go评论92阅读模式
英文:

HIVE SQL where clause not working as expected

问题

我只想返回包含 "F" 的 "field1" 字段,但它却返回了任何包含 "F" 的值。是不是 "_" 没有被考虑进去?

例如:
Field1
JBHi-Fi
JBHIFI_F_1234

从表1中选择所有行
其中 "field1" 匹配 "%F%"

英文:

I have a where clause where I only want to return records where field1 contains "F" but it's picking any value which contains "F" does the "_" not get looked at?

Eg.
Field1
JBHi-Fi
JBHIFI_F_1234

select * from table1
where field1 like "%_F_%"

答案1

得分: 1

_被视为通配符,类似于%,表示搜索1个字符。因此,您的查询与'%F%'一样好。如果要搜索类似%_F_%'的模式,则需要使用这个\作为转义字符。
使用

where field1 like "%\_F\_%"

<details>
<summary>英文:</summary>

`_` is considered as wild card like `%` and it means search for 1 character. So, your query is as good as `&#39;%F%&#39;`. If you want to search for a pattern like `%_F_%&#39;` then you need to use this \ as escape character.   
Use 

where field1 like "%_F_%"

huangapple
  • 本文由 发表于 2023年5月30日 09:37:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76361118.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定