我的表列包含如下值:
id | item
-------------
1 | aaaa11a112
2 | aa1112aa2a
3 | aa11aa1a11
4 | aaa2a222aa
我只想选择项目值以数字结尾的行。
有这样的事吗?
select * from table where item like '%number'
您可以使用REGEXP
和字符类
select * from table where item REGEXP '[[:digit:]]$'
DEMO http://sqlfiddle.com/#!9/8b195/2
解释:
[[:digit:]] >> Match digit characters
$ >> Match at the end of the string
在方括号表达式(使用 [ 和 ] 编写)中,[:character_class:] 表示匹配属于该类的所有字符的字符类。
边注:
其他有用的 mysql 字符类一起使用REGEXP
,取自文档 https://dev.mysql.com/doc/refman/5.6/en/regexp.html#operator_regexp:
Character Class Name Meaning
alnum Alphanumeric characters
alpha Alphabetic characters
blank Whitespace characters
cntrl Control characters
digit Digit characters
graph Graphic characters
lower Lowercase alphabetic characters
print Graphic or space characters
punct Punctuation characters
space Space, tab, newline, and carriage return
upper Uppercase alphabetic characters
xdigit Hexadecimal digit characters
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)