mysql字符串结束符,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'

解决方案

You can use REGEXP and character class

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

Explanation:

[[:digit:]] >> Match digit characters

$ >> Match at the end of the string

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

SIDENOTE:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值