"AND" va "BETWEEN" mantiqiy operatorlariga doir savollarga yechimlar.
SELECT *
FROM talaba
WHERE yosh > 16 AND yosh <20;
"accounts" jadvalidan foydalanib, "C" harfi bilan boshlanmaydigan va "s" harfi bilan tugaydigan barcha kompaniyalarni toping.
SELECTname FROM talaba
WHEREnameNOTLIKE 'C%' ANDnameLIKE '%s';
SQLda "BETWEEN" operatoridan foydalanib 20 yoshdan 26 yoshgacha bo’lgan talabalarni topamiz.
SELECT *
FROM talaba
WHERE yosh BETWEEN 20 AND 26;
BETWEEN operatorini sanalar uchun ishlatish qiyin ekanligiga guvoh bo‘lasiz. BETWEEN odatda tugatish nuqtalarini o‘z ichiga olgan holda, vaqt sanalar uchun soat 00:00da (ya‘ni yarim tunda) bo‘lganligini anglatadi. Shu sababli tugash nuqtasining o‘ng tomonini '2017-01-01'ga o‘rnatdik.
SELECT *
FROM talabalar
WHERE FISH IN ('Aliyev Vali', 'Valiyev Ali') AND tyil BETWEEN '2016-01-01' AND '2017-01-01'
ORDERBY occurred_at DESC;
AND operatoriga o‘xshab, OR operatori bir nechta iboralarni birlashtirishi mumkin. Har safar yangi iborani OR operatori bilan bog‘laganingizda, qarash kerak bo‘lgan ustunni ko‘rsatishingiz kerak. Bir vaqtning o‘zida ko‘rib chiqishni istagan ko‘plab kod bayonotlarini bog‘lashingiz mumkin. Ushbu operator hozirgacha ko‘rib chiqqan barcha amallar bilan ishlaydi, shu jumladan arifmetik operatorlar (+, *, -,/), LIKE, IN, NOT, AND va BETWEEN mantiqiy operatorlarni OR operatoridan foydalangan holda bir biriga ulash mumkin.
Bir nechta amallarni birlashtirganda, bajarilishi lozim bo‘lgan mantiq to‘g‘ri bajarilganligiga ishonch hosil qilish uchun ko‘pincha qavslardan foydalanishimiz kerak bo‘ladi.
"OR" operatoriga doir savollarning yechimlari
1.
SELECTid FROM talaba
WHERE yosh > 20 OR staj > 5;
2.
SELECT *
FROM talaba
WHERE standard = 0 AND (yosh > 20 OR staj>5);
3.
SELECT *
FROM talaba
WHERE (nameLIKE 'C%' ORnameLIKE 'W%')