我的表格列包含以下值:
id | item
-------------
1 | aaaa11a112
2 | aa1112aa2a
3 | aa11aa1a11
4 | aaa2a222aa
我想只选择项目值以数字结尾的行。 有这样的事吗?
select * from table where item like '%number'
答案 0 :(得分:17)
您可以使用REGEXP
和字符类
select * from table where item REGEXP '[[:digit:]]$'
说明:
[[:digit:]] >> Match digit characters
$ >> Match at the end of the string
在括号表达式中(使用[和]编写),[:character_class:]表示与属于该类的所有字符匹配的字符类。
旁注:
用于REGEXP
的其他有用的mysql字符类,取自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
答案 1 :(得分:2)
您可以使用select * from table where RIGHT(item ,1) REGEXP '^-?[0-9]+$';
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-md-3">
<div class="sidebar_container">
<div class="logo_container">
<img class="logo_img" src="img/logo_bg.png" alt="" title="" />
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
<div class="col-xs-12 col-md-9 main-content">
<div class="row section1">
<div class="col-xs-12 col-md-6 left">
<h4 class="header_title desktop">Feature One</h3>
<p class="btns desktop"><a class="link" href="#"><button class="f_button">Find out more</button ></a></p>
</div>
<div class="col-xs-12 col-md-6 right">
<img src="img/section1_bg.png" class="bg_image">
<h4 class="header_title mobile">Feature One</h3>
<p class="btns mobile"><a class="link" href="#"><button class="f_button">Find out more</button></a></p>
</div>
</div>
<div class="row section2">
<div class="col-xs-12 col-md-9 left"><img src="img/section2_bg.png" class="bg_image"></div>
<div class="col-xs-12 col-md-3 right">
<h4 class="header_title">Feature Two</h3>
<p><a class="link" href="#"><button class="f_button">Find out more</button></a></p>
</div>
</div>
<div class="row section3">
<div class="col-xs-12 col-md-3 left">
<h4 class="header_title desktop">Feature Three</h3>
<p class="btns desktop"><a class="link" href="#"><button class="f_button">Find out more</button></a></p>
</div>
<div class="col-xs-12 col-md-9 right">
<img src="img/section3_bg.png" class="bg_image">
<h4 class="header_title mobile">Feature Three</h3>
<p class="btns mobile"><a class="link" href="#"><button class="f_button">Find out more</button></a></p>
</div>
</div>
<div class="row section4">
<div class="col-xs-12 col-md-8 left">
<img src="img/section4_bg.png" class="bg_image">
</div>
<div class="col-xs-12 col-md-4 right">
<h4 class="header_title">Feature Four</h3>
<p><a class="link" href="#"><button class="f_button">Find out more</button ></a></p>
</div>
</div>
</div>
</div>
</div>
答案 2 :(得分:-2)
是的,您可以将数字用于数字。
select * from table where item like '%1'
这将有效