BETWEEN命令用于选择给定范围内的值。值可以是数字,文本或日期。
BETWEEN命令具有包容性:包括开始值和结束值。
以下SQL语句选择价格介于10和20之间的所有产品:
SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;
要显示上一个示例范围之外的产品,请使用NOT BETWEEN:
SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20;
以下SQL语句选择“ Carnarvon Tigers”和“ Mozzarella di Giovanni”之间具有ProductName的所有产品:
SELECT * FROM Products WHERE ProductName BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni' ORDER BY ProductName;