DBMS - Worksheet 8 & 9 - Answers
DBMS - Worksheet 8 & 9 - Answers
----------Question 1--------
----------Question 02 -------------
update Activity
set Coach = case
when AID = 'Swimming' then 'Kevin'
when AID = 'Golf' then 'Jagath'
when AID = 'Sailing' then 'Dev'
when AID = 'Tennis' then 'Manju'
when AID = 'Cricket' then 'Peter'
when AID = 'Badminton' then 'Ravi'
end;
----------Qeustion 5----------
update Player set Age = 6 where ID = 101;
update Player set Pname = 'Deva' where ID = 121;
-----------Question 6 ----------
delete from Player where ID =107;
-----------Question 7 ----------
insert into Player values (123, 'Jim', 12, 'Thurstan College');
insert into Participate values (123,'Sailing');
insert into Participate values (123,'Swimming');
-----------Question 8 ----------
a) select distinct Pname from Player;
b) select * from Activity where cost<5000;
c) select * from Player where Pname like '[G-R]%' order by Pname desc;
d) select * from Player where Pname like '_e%';
e) select * from Player where Age<20 and Age>10;
f) select max(Age) as MaxAge from Player;
g) select School, count(*) as NumbeOfStudents from Player group by School;
h)
select Player.Pname, Player.School, Activity.AID, Activity.Coach from Player
join Participate on Player.ID = Participate.ID
join Activity on Participate.AID = Activity.AID;
p)
select A.Coach, sum(A.Cost *count(PT.ID)) as TotalEarnings
from Activity A
left join Participate PT on A.AID = PT.AID
group by A.Coach;
----------Worksheet 9-----------
---------------Question 01--------------
insert into Participate values (114, 'Tennis');
insert into Participate values (121,'Tennis');
insert into Participate values (102, 'Sailing');
---------------Question 02--------------
a) select Pname from Player where Age = (select min(Age) from Player);
c) select * from Player where School = (select School from Player where Pname =
'Methmi');
d) select * from Player where Age > (select avg(Age) from Player);
e) select AID from Activity where Cost = (select max(Cost) from Activity);
f) select AID from Activity where Cost = (select min(Cost) from Activity);
g) select Coach from Activity where Cost = (select max(Cost) from Activity);
h) select * from Player where Age = (select Age from Player where ID = 100)
or Age = (select Age from Player where ID = 107);
i) select * from Activity where Cost != (select Cost from Activity where AID =
'Sailing')
and Cost != (select Cost from Activity where AID = 'Swimming');