vend_name
|
vend_name_upcase
|
Bear Emporium
|
BEAR EMPORIUM
|
Bears R Us
|
BEARS R US
|
Doll House Inc.
|
DOLL HOUSE INC.
|
Fun and Games
|
FUN AND GAMES
|
Furball Inc.
|
FURBALL INC.
|
Jouets et ours
|
JOUETS ET OURS
|
2) LOWER() funksiyasi
SELECT vend_name, LOWER(vend_name) AS vend_name_lowcase FROM Vendors ORDER BY vend_name;
vend_name
|
vend_name_lowcase
|
Bear Emporium
|
bear emporium
|
Bears R Us
|
bears r us
|
Doll House Inc.
|
doll house inc.
|
Fun and Games
|
fun and games
|
Furball Inc.
|
furball inc.
|
Jouets et ours
|
jouets et ours
|
2) LEFT() funksiyasi
SELECT FacultetNom LEFT(FacultetNom,3) AS QisqachaNom FROM facultet;
6.2. Raqamli funksiyalar
Funksiya
|
Qaytuvchi qiymat
|
ABS()
|
Sonning moduli
|
COS()
|
Berilgan burchakning kosinusi
|
EXP()
|
Berilgan sonning ko‘rsatkichi
|
PI()
|
soni
|
SIN()
|
Berilgan burchakning sinusi
|
SQRT()
|
Berilgan sonning kvadrat ildizi
|
TAN()
|
Berilgan burchakning tangensi
|
6.3. Jami hisob funksiyalari
Funksiya
|
Qaytuvchi qiymat
|
AVG()
|
Ustun bo’yicha qiymatlarning o’rtachasi
|
COUNT()
|
Ustundagi qatorlar soni
|
MAX()
|
Ustundagi eng katta qiymat
|
MIN()
|
Ustundagi eng kichik qiymat
|
SUM()
|
Ustundagi qiymatlar yig’indisi
|
Topshiriq. Yuqoridagi funksiyalarni jadvallarda qo’llab so’rovlar hosil qiling
7-TOPSHIRIQ. TRANZAKSIYALAR
Tranzaksiyalarni boshqarish. Tranzaksiyalarni boshqarish uchun quyidagi buyruqlardan foydalaniladi:
COMMIT - O'zgarishlarni saqlaydi
ROLLBACK - O'zgarishlarni qaytaradi (bekor qilish)
SAVEPOINT - Tranzaksiyalar guruhi orqaga qaytarishi mumkin bo'lgan nuqtani yaratadi
SET TRANSACTION - Tranzaksiya nomini joylashtiradi.
Tranzaktsiyalarni boshqarish buyruqlari faqat DML buyruqlari uchun ishlatiladi: INSERT, UPDATE, DELETE. Ularni jadval yaratish, o'zgartirish yoki yo'q qilish paytida ishlatib bo'lmaydi.
Misollar:
Ishni boshlashdan oldin, avtomatik tranzaktsiyalarni bajarilishini o'chirish uchun quyidagi buyruqni bajaring:
mysql> SET autocommit=0;
Aytaylik, bizda developers jadvali quyidagi yozuvlarni o'z ichiga oladi:
+----+-------------------+-----------+------------+--------+
| ID | NAME | SPECIALTY | EXPERIENCE | SALARY |
+----+-------------------+-----------+------------+--------+
| 1 | Eugene Suleimanov | Java | 2 | 2500 |
| 2 | Peter Romanenko | Java | 3 | 3500 |
| 3 | Andrei Komarov | C++ | 3 | 2500 |
| 4 | Konstantin Geiko | C# | 2 | 2000 |
| 5 | Asya Suleimanova | UI/UX | 2 | 1800 |
| 7 | Ivan Ivanov | C# | 1 | 900 |
| 8 | Ludmila Geiko | UI/UX | 2 | 1800 |
+----+-------------------+-----------+------------+--------+
Quyidagi buyruq bilan C ++ dasturchilarining barchasini o'chirib tashlang:
mysql> DELETE FROM developers
WHERE SPECIALTY = 'C++';
mysql> COMMIT;
Ushbu so'rovni bajarish natijasida bizning jadval quyidagi yozuvlarni o'z ichiga oladi:
+----+-------------------+-----------+------------+--------+
| ID | NAME | SPECIALTY | EXPERIENCE | SALARY |
+----+-------------------+-----------+------------+--------+
| 1 | Eugene Suleimanov | Java | 2 | 2500 |
| 2 | Peter Romanenko | Java | 3 | 3500 |
| 4 | Konstantin Geiko | C# | 2 | 2000 |
| 5 | Asya Suleimanova | UI/UX | 2 | 1800 |
| 7 | Ivan Ivanov | C# | 1 | 900 |
| 8 | Ludmila Geiko | UI/UX | 2 | 1800 |
+----+-------------------+-----------+------------+--------+
Endi
Do'stlaringiz bilan baham: |