英文:
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 `'%F%'`. If you want to search for a pattern like `%_F_%'` then you need to use this \ as escape character.
Use
where field1 like "%_F_%"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论