mysql,字符串以数字结尾 [英] mysql where string ends with numbers

查看:982
本文介绍了mysql,字符串以数字结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格列包含以下值:

My table column contains values like:

id | item
-------------
1  | aaaa11a112
2  | aa1112aa2a
3  | aa11aa1a11
4  | aaa2a222aa

我只想选择项目值以数字结尾的行. 有这样的东西吗?

I want to select only rows where value of item ends with numbers. Is there something like this?

select * from table where item like '%number'

推荐答案

您可以使用REGEXP和字符类

select * from table where item REGEXP '[[:digit:]]$'

演示

说明:

[[:digit:]] >> Match digit characters
$           >> Match at the end of the string

在方括号表达式(用[和]编写)中,[:character_class:]表示与该类所有字符匹配的字符类.

Within a bracket expression (written using [ and ]), [:character_class:] represents a character class that matches all characters belonging to that class.

旁注:

REGEXP一起使用的其他有用的mysql字符类,取自

Other helpful mysql character classes to use with REGEXP, taken from the documentation:

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

这篇关于mysql,字符串以数字结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆