包含边界的,如下:between...prar1 and prar2 相当于>=prar1 and <=prar2
mysql>
SELECT * FROM employee_tbl
->
WHERE daily_typing_pages >= 170 AND
->
daily_typing_pages <= 300
+------+------+------------+--------------------+
|
id | name | work_date | daily_typing_pages |
+------+------+------------+--------------------+
| 1 | John | 2007-01-24 | 250 |
| 2 | Ram | 2007-05-27 | 220 |
| 3 | Jack | 2007-05-06 | 170 |
| 4 | Jill | 2007-04-06 | 220 |
| 5 | Zara | 2007-06-06 | 300 |
+------+------+------------+--------------------+
5 rows in set (0.03 sec)
如果用between 2 and 4
相当于大于等于2
小于等于4
mysql的sql语句中可以使用between来限定一个数据的范围,例如:select * from user where userId between 5 and 7查询userId为5、6,7的user,userId范围是包含边界值的,也等同如下查询:select * from user where userId >= 5 and userId <= 7很多地方都提到between是给定的范围是大于等第一值,小于第二个值,其实这是不对的。此前我一直也是这么认为,通过实验,结论是包含两边的边界值,如果实在拿不准,可以采用>= 、<=的方式来指定条件。另外 not between的范围是不包含边界值。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)