SQL BETWEEN
在上篇IN語句中運用一個或多個值來取得,而BETWEEN 不同的是可運用一個範圍內抓取資料,並將該欄位包含在值一及值二之間
SELECT * FROM 資料表 WHERE 欄位1 BETWEEN 值 AND 值;
SELECT * FROM Products where BETWEEN UnitPrice 20 AND 30 ;
ProductID |
ProductName |
QuantityPerUnit |
UnitPrice |
UnitsInStock |
1 |
Chai |
10 boxes x 20 bags |
18.00 |
39 |
2 |
Chang |
24 - 12 oz bottles |
19.00 |
17 |
3 |
Aniseed Syrup |
12 - 550 ml bottles |
10.00 |
13 |
4 |
Queso Manchego La Pastora |
10 - 500 g pkgs. |
38.00 |
86 |
5 |
Konbu |
2 kg box |
6.00 |
24 |
6 |
Tofu |
40 - 100 g pkgs. |
23.25 |
35 |
7 |
Teatime Chocolate Biscuits |
10 boxes x 12 pieces |
9.20 |
25 |
8 |
Carnarvon Tigers |
16 kg pkg. |
62.50 |
42 |
9 |
Grandma's Boysenberry Spread |
12 - 8 oz jars |
25.00 |
120 |
10 |
Sir Rodney's Marmalade |
30 gift boxes |
81.00 |
40 |
結果:
ProductID |
ProductName |
QuantityPerUnit |
UnitPrice |
UnitsInStock |
6 |
Tofu |
40 - 100 g pkgs. |
23.25 |
35 |
9 |
Grandma's Boysenberry Spread |
12 - 8 oz jars |
25.00 |
120 |