查询以选择以某些字符结尾的字符串 [英] Query to select strings end with certain character
本文介绍了查询以选择以某些字符结尾的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一列包含以下字符串:
I have a column that contains strings as:
aaa_1
aaa_11
我需要查询以_1
结尾的字符串.我尝试了以下方法:
从表中选择col,其中col如%_1
;
但是查询给了我以_1
和_11
结尾的字符串.我该如何纠正呢?
I need to query strings that ends with _1
. I tried the following:
select col from table where col like %_1
;
But the query gives me the strings that ends with _1
and _11
. How can I correct this ?
推荐答案
尝试一下:
select col from table where col like '%\_1'
字符_
是一个欢乐,就像%,但是它只匹配一个字符,因此您必须使用\
character _
is a jolly, like %, but it matches only a single character, so you have to escape it with \
请参见此处: http://dev .mysql.com/doc/refman/5.0/zh-CN/string-comparison-functions.html#operator_like
这篇关于查询以选择以某些字符结尾的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文