Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql,其中字符串以数字结尾_Mysql - Fatal编程技术网

mysql,其中字符串以数字结尾

mysql,其中字符串以数字结尾,mysql,Mysql,“我的表”列包含如下值: id | item ------------- 1 | aaaa11a112 2 | aa1112aa2a 3 | aa11aa1a11 4 | aaa2a222aa 我只想选择项目值以数字结尾的行。 有这样的东西吗 select * from table where item like '%number' 您可以使用REGEXP select * from table where RIGHT(item ,1) REGEXP '^-?[0-9]+$';

“我的表”列包含如下值:

id | item
-------------
1  | aaaa11a112
2  | aa1112aa2a
3  | aa11aa1a11
4  | aaa2a222aa
我只想选择项目值以数字结尾的行。 有这样的东西吗

select * from table where item like '%number'

您可以使用
REGEXP

select * from table where  RIGHT(item ,1) REGEXP '^-?[0-9]+$';

是的,你可以用like来表示数字

select * from table where item like '%1'

这将起作用

您可以使用
REGEXP
和字符类

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

说明:

[[:digit:]] >> Match digit characters
$           >> Match at the end of the string
在括号表达式(使用[and]编写)中,[:character_class:]表示与属于该类的所有字符匹配的字符类


旁注:

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


仅最后一个字符或多个字符?请参见:
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