BETWEEN命令用于選擇給定范圍內(nèi)的值。值可以是數(shù)字,文本或日期。
BETWEEN命令具有包容性:包括開始值和結(jié)束值。
以下SQL語句選擇價格介于10和20之間的所有產(chǎn)品:
SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;
要顯示上一個示例范圍之外的產(chǎn)品,請使用NOT BETWEEN:
SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20;
以下SQL語句選擇“ Carnarvon Tigers”和“ Mozzarella di Giovanni”之間具有ProductName的所有產(chǎn)品:
SELECT * FROM Products WHERE ProductName BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni' ORDER BY ProductName;