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的范圍是不包含邊界值。