=Start=
缘由:
之前在写一个Web应用的时候碰到过类似的问题,当时也不清楚between的边界到底是个什么情况,就用「>/>=/</<=」替换了。今天又碰到了,索性彻底了解一下。
正文:
参考解答:
官网上的说明:
If
expr
is greater than or equal tomin
andexpr
is less than or equal tomax
,BETWEEN
returns1
, otherwise it returns0
. This is equivalent to the expression(
if all the arguments are of the same type. Otherwise type conversion takes place according to the rules described in Section 13.2, “Type Conversion in Expression Evaluation”, but applied to all the three arguments.min
<=expr
ANDexpr
<=max
)
即,MySQL的between是包含两边的边界值的,等价于「min <=expr AND expr <= max」。
另外一个「not between」:
This is the same as
NOT (
.expr
BETWEENmin
ANDmax
)
所以,「not between」是对「between」的取反,则不包含边界值,等价于「expr < min OR expr > max」。
参考链接:
- http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_between
- http://www.netingcn.com/mysql-between.html
=END=