|
Tekshirdi: Boboqulov Abbos toshkent – 2023 7-topshiriq
|
Sana | 24.07.2024 | Hajmi | 2,61 Mb. | | #268439 |
O‘ZBEKISTON RESPUBLIKASI RAQAMLI TEXNOLOGIYALAR VAZIRLIGI MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Ma‘lumotlar bazasi
Amaliy ish №7,8,9
Bajardi: Abdusattorov Akbar.
DBM004-1 guruh talabasi
Tekshirdi: Boboqulov Abbos
TOSHKENT – 2023
7-topshiriq: UNION, INTERSECT va MINUS standart so‘zlaridan foydalanish
2 ta jadval yaratamiz:
create table users(
id int primary key auto_increment,
first_name varchar(60),
last_name varchar(60),
born_year int,
email varchar(60)
)
create table students(
id int primary key auto_increment,
first_name varchar(60),
last_name varchar(60),
born_year int,
gpa float,
email varchar(60)
)
Ularga mockaro orqali mock data kiritamiz.
Natija:
UNION buyrug’i:
select id, first_name,born_year from students
union
select id, first_name,born_year from users order by id;
Intersect buyrugi:
Buning natijasini ko’rish uchun 2 la jadvalga bir xil bo’lgan bir nechta qiymat qo’shish kerak.
select first_name,born_year from students
INTERSECT
select first_name,born_year from users;
MINUS(EXCEPT) buyrugi:
select first_name,born_year from students
except
select first_name,born_year from users;
8-topshiriq: Bir nеchta jadvallar birlashtirish, JOINlar bilan ishlash
Buning uchun quyidagicha jadvallarni yaratib olamiz:
create table Kafedralar(
kafedra_id int primary key auto_increment,
kafedra_nomi varchar(50)
);
create table Xodimlar(
xodim_id int primary key auto_increment,
first_name varchar(30) not null,
last_name varchar(40) not null,
lavozim varchar(30) not null,
education text not null,
kafedra_id int,
foreign key (kafedra_id) references Kafedralar(kafedra_id)
);
Xodimlar jadvali:
Kafedralar
Inner join
select * from Xodimlar inner join Kafedralar on Xodimlar.kafedra_id = Kafedralar.kafedra_id;
Left join:
select * from Xodimlar left join Kafedralar on Xodimlar.kafedra_id = Kafedralar.kafedra_id;
Right join:
select * from Xodimlar right join Kafedralar on Xodimlar.kafedra_id = Kafedralar.kafedra_id;
Cross join:
select * from Xodimlar cross join Kafedralar on Xodimlar.kafedra_id = Kafedralar.kafedra_id;
Full outer join:
select * from Xodimlar left join Kafedralar on Xodimlar.kafedra_id = Kafedralar.kafedra_id
union
select * from Xodimlar right join Kafedralar on Xodimlar.kafedra_id = Kafedralar.kafedra_id ;
9-topshiriq.
1.
2.
3.
4.
5.
6.
7.
|
| |