BETWEEN operator

BETWEEN operator belgilangan diapazondagi qiymatlarni tanlaydi.

SU

SQL BETWEEN Operator

BETWEEN operator belgilangan diapazondagi qiymatlarni tanlaydi. Qiymatlar raqamlar, matn yoki sanalar bo'lishi mumkin.

BETWEEN operatori qamrovli hisoblanadi: boshlanish va tugash qiymatlari ham kiritiladi.

Misol

Narxi 10 dan 20 gacha bo'lgan barcha mahsulotlarni tanlash:

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;

Sintaksis

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

Demo Ma'lumotlar Bazasi

Quyida misollarda ishlatilgan Products jadvidan tanlov keltirilgan:

ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars22
5Chef Anton's Gumbo Mix2236 boxes21.35

NOT BETWEEN

Avvalgi misoldagi diapazondan tashqaridagi mahsulotlarni ko'rsatish uchun NOT BETWEEN dan foydalaning:

Misol:

SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;

BETWEEN IN bilan

Quyidagi SQL bayonoti narxi 10 dan 20 gacha bo'lgan barcha mahsulotlarni tanlaydi. Bundan tashqari, CategoryID 1, 2 yoki 3 bo'lishi kerak:

Misol:

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20
AND CategoryID IN (1,2,3);

Matn Qiymatlari Bo'yicha BETWEEN

Quyidagi SQL bayonoti mahsulot nomi alphabetik jihatdan 'Carnarvon Tigers' va 'Mozzarella di Giovanni' o'rtasida bo'lgan barcha mahsulotlarni tanlaydi:

Misol:

SELECT * FROM Products
WHERE ProductName BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni'
ORDER BY ProductName;

Quyidagi SQL bayonoti mahsulot nomi 'Carnarvon Tigers' va 'Chef Anton's Cajun Seasoning' o'rtasida bo'lgan barcha mahsulotlarni tanlaydi:

Misol:

SELECT * FROM Products
WHERE ProductName BETWEEN "Carnarvon Tigers" AND "Chef Anton's Cajun Seasoning"
ORDER BY ProductName;

NOT BETWEEN Matn Qiymatlari

Quyidagi SQL bayonoti mahsulot nomi 'Carnarvon Tigers' va 'Mozzarella di Giovanni' o'rtasida bo'lmagan barcha mahsulotlarni tanlaydi:

Misol:

SELECT * FROM Products
WHERE ProductName NOT BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni'
ORDER BY ProductName;

SANALARGA BO'YICHA BETWEEN

Quyidagi SQL bayonoti '01-July-1996' va '31-July-1996' o'rtasida barcha buyurtmalarni tanlaydi:

Misol:

SELECT * FROM Orders
WHERE OrderDate BETWEEN #07/01/1996# AND #07/31/1996#;

Yoki:

Misol:

SELECT * FROM Orders
WHERE OrderDate BETWEEN '1996-07-01' AND '1996-07-31';

Namuna Jadvali

Quyida misollarda ishlatilgan Orders jadvidan tanlov keltirilgan:

OrderIDCustomerIDEmployeeIDOrderDateShipperID
102489057/4/19963
102498167/5/19961
102503447/8/19962
102518437/9/19961
102527647/10/19962

Ushbu sahifada

Xato haqida xabar berish