Name:badr mohammed kamal tohamy Code:220105 class (3) TASK.1 create table manufactureres ( m_code int primary key not null, m_name varchar(20) not null, ) create table products ( p_code int primary key not null, p_name varchar(20) not null, p_price int not null, manufactureres int foreign key references manufactureres (m_code) ) select m_name from manufactureres m , products p where m_code = p_code and p_price >=30 --2 select AVG (p_price) as avrg_price , m_name from manufactureres ,products where m_code= p_code group by m_name --3 select m_name , AVG (p_price) as avrg_price from manufactureres ,products where m_code= p_code group by m_name --4 select COUNT(*)as number_of_column from products where p_name = 'printer' --5 select (.9* p_price) as discount_price from products where p_price >=40 --6 select m_name ,p_name , p_price from manufactureres join products on m_code =products.manufactureres where p_price =( select MAX (p_price) from products ) --7 select m_name ,p_name , p_price from manufactureres join products on m_code =products.manufactureres where p_price =( select min (p_price) from products ) --8 select p_name ,p_price from products where p_price >= 40 order by p_price desc ,p_name asc; select top 1 p_name ,p_price from products order by p_price desc; TASK.2 TASK.3 TASK.4 . create database page5 ; create table ratial_ceter( id int identity(1,1) primary key, typ_e varchar(50), adress varchar(50) ); create table items ( num int identity(1,1) primary key, weights int , dimentions varchar(50), destinations int , final_date date, insurance_amount varchar(50) , r_id int foreign key references ratial_ceter(id), ); create table transportion( num int identity(1,1) primary key, typ_e varchar(50), deliver varchar(50), ); create table items_transportion ( i_num int foreign key references items (num), t_num int foreign key references transportion(num) , primary key (i_num , t_num), ); alter table ratial_ceter alter column typ_e varchar(20); alter table retial_ceter add locations varchar(50); update ratial_ceter set typ_e ='recycle' where id=111; TASK.5 create table custmor ( c_id int primary key not null, c_name varchar(20) not null, c_address varchar(20) not null, c_contact varchar(20) null, c_credit int not null, ) create table manufacturer ( m_id int primary key not null, m_name varchar (20) not null, m_address varchar(50) null, m_contact varchar(20) null, ) create table product ( p_id int primary key not null, p_name varchar (20) not null, p_color varchar (20) null, p_date varchar (20) not null, m_id int not null, ) create table ordeer ( o_id int primary key not null, c_id int not null, o_reference varchar (20) null, o_purchase_date varchar (50) not null, ) create table order_items ( o_id int primary key not null, p_id int not null, or_qty int not null, or_unit_price int not null, ) insert into product(p_id , p_name, p_color ,p_date ,m_id) values(1,'royal','red',01012003,1) insert into product(p_id , p_name, p_color ,p_date ,m_id) values(2,'aryal','green',01012006,2) insert into product(p_id , p_name, p_color ,p_date ,m_id) values(3,'oxi','gray',01012004,3) insert into product(p_id , p_name, p_color ,p_date ,m_id) values(4,'perciel','white',01012005,4) insert into product(p_id , p_name, p_color ,p_date ,m_id) values(5,'vatika','red',01012020,5) insert into ordeer (o_id ,c_id,o_reference,o_purchase_date) values(1,1,'good',01012019) insert into ordeer (o_id ,c_id,o_reference,o_purchase_date) values(2,2,'bad',01012003) insert into ordeer (o_id ,c_id,o_reference,o_purchase_date) values(3,3,'wonderful',01012006) insert into ordeer (o_id ,c_id,o_reference,o_purchase_date) values(4,4,'bad',01012020) insert into ordeer (o_id ,c_id,o_reference,o_purchase_date) values(5,5,'nice',01012023) insert into custmor(c_id,c_name,c_address,c_contact,c_credit) values (1,'badr','bns','phone',100) insert into custmor(c_id,c_name,c_address,c_contact,c_credit) values (2,'osama','bns','facebook',150) insert into custmor (c_id,c_name,c_address,c_contact,c_credit) values (3,'ali','alex','watsapp',200) insert into custmor (c_id,c_name,c_address,c_contact,c_credit) values (4,'mohammed','menia','instgram',120) insert into custmor (c_id,c_name,c_address,c_contact,c_credit) values (5,'ahmed','bns','tweter',130) insert into manufacturer (m_id,m_name,m_address,m_contact) values (1,'tiger','bns','phone') insert into manufacturer (m_id,m_name,m_address,m_contact) values (2,'pepsi','bns','facebook') insert into manufacturer (m_id,m_name,m_address,m_contact) values (3,'cocacola','alex','watsapp') insert into manufacturer (m_id,m_name,m_address,m_contact) values (4,'gohaina','menia','instgram') insert into manufacturer (m_id,m_name,m_address,m_contact) values (5,'mraie','qena','tweter') insert into order_items (o_id, p_id , or_qty ,or_unit_price) values(1,1,10,100) insert into order_items (o_id, p_id , or_qty ,or_unit_price) values(2,2,20,120) insert into order_items (o_id, p_id , or_qty ,or_unit_price) values(3,3,30,130) insert into order_items (o_id, p_id , or_qty ,or_unit_price) values(4,4,15,140) insert into order_items (o_id, p_id , or_qty ,or_unit_price) values(5,5,40,150) --1 delete from ordeer --2 select* from product --3 select* from product where p_color = 'red' --4 select* from manufacturer order by m_name --5 select c_name as custmor_name from custmor --6 insert into custmor(c_id,c_name,c_address,c_contact,c_credit) values (6,'badr','bns','phone',100) --7 select* from order_items where or_qty>20 --8 select* from order_items where or_unit_price in (120,130,150) --9 select* from product where p_date between 01012003 and 01012020 TASK.6 create table bbranch( branchno int identity(1,1) primary key , street varchar(50), city varchar(50), post_code int ); create table sttaff ( staffno int identity(1,1) primary key , fname varchar(50) , lname varchar(50) , possition varchar(50), sex varchar(50), dob date , salary int , branchno int foreign key references (branchno), ); create table cllient ( clientno int identity(1,1) primary key , fname varchar(50), lname varchar(50), telno varchar(50), preftype varchar(50), maxrent varchar(50), ); create table private_owner ( ownerno int identity(1,1) primary key , fname varchar(50), lname varchar(50), telno varchar(50), adress varchar(50), ); create table prropertyforrent( propertyno int not null primary key, street_property varchar(10), city_property varchar(10), postcode_property int , propertytype varchar(10), rooms varchar(10), rent int, ownerno int foreign key references private_owner(ownerno), staffno int foreign key references 'staff' (staffno), branchno int foreign key references 'branch' (branchno)); create table viiewing ( viewdate date, comment varchar(20), clientno int foreign key references client(clientno), propertyno int foreign key references propertyforrent(propertyno) primary key (clientno,propertyno) ); 2/ select * from staff; 3/ select staffNo,lname,fname,salary from staff; 4 / select count(*) from propertyForRent p join viewing v on p.PropertyNo=v.PropertyNo; 6/select * from staff where salary>10000; 7/ select address from privateOwner p join propertyForRent p2 on p.ownerNo=p2.ownerNo join Branch b on b.BranchNo=p2.BranchNo where b.City in ('london','Glasgow'); 8/ select * from staff where salary between 20000 and 30000; 9/ select * from staff where position in ('manager','supervisor'); 10/ select * from PrivateOwner p where p.address like '%Glasgow%'; 11/ select * from viewing v join PropertyForRent p on v.PropertyNo=p.PropertyNo where v.Comment=NULL; 12/ select Salary from staff order by Salary desc; 13/ select * from PropertyForRent order by PropertyType; 14/ select count(*) from PropertyForRent p where p.Rent>350; 15/ select count(*) from viewing v where v.ViewDate='may-2001'; 16/ select count(*) , sum(s.Salary) from staff s where s.position='manager'; 17/ select min(s.Salary),max(s.Salary),avg(s.Salary) from staff s; 18/ select count(*) ,sum(s.Salary) from staff s join Branch b on s.BranchNo=b.BranchNo group by postcode; 19/ update staff set Salary=Salary+(3/100)*Salary; 20/ update staff set Salary=Salary+(5/100)*Salary where position='manager'; 21/ update staff set Salary=18000,position='manager' where fName='David' and lName='Ford'; 22/ delete * from viewing v join PropertyForRent p on v.PropertyNo=p.PropertyNo where p.postcode='PG4'; 23/ drop table viewing; 24/ select fname,lname, from staff where position='manager'; 25/ select count(*),sum(s.Salary) from staff s join Branch b on s.BranchNo=b.BranchNo group by postcode having count(*)>1; select count(*)as "total managers",sum(salary)from staff where possition="Manager" --26-select fname, lname FROM client inner join viewing where client.clientno=viewing .clientno --27 SELECT b.branchno, b.city, s.staffno, fname, lname, propertyno FROM Branch AS b, Staff AS s, propertyforRent p WHERE b.branchNo = s.branchNo AND s.staffno=p.staffno --28- SELECT S.branchno , S.staffno , COUNT(*) AS "count" FROM staff S , propertyforrent P WHERE S.staffno = P.staffno GROUP BY S.branchno , S.staffno ORDER BY S.staffno;