






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Mingsong Chen Wenjie Yuan
Solutions
Name: UFID: Email Address:
Pledge (Must be signed according to UF Honor Code)
On my honor, I have neither given nor received unauthorized aid in doing this assignment.
_______________________________________________Signature
For scoring use only:
Maximum Received Exercise 1 14
Exercise 2 36
Exercise 3(a) 15 Exercise 3(b) 35
Total 100
football_ players fid fname rating age _id P._S
football_ players fid fname rating age ┐ _id >4 <
Print average ages by rating. football_ players fid fname rating age G.P _A P.AVG._A
Print ratings for which the average age is more than 30. football_ players fid fname rating age G.P _A
Conditions AVG._A > 30
Reserves fid pid day _id _B _B
Conditions COUNT._B1 =COUNT._B
Conditions _A<20 OR 30<_A
insert information into the database about a new football player Janice whose id is 74, rating is 7 and age is 41. football_ players fid fname rating age I. 74 Janice 7 41
Update the age of the football player with sid 74 to be 42 years. football_ players fid fname rating age 74 U.
(A) Two queries are said to be equivalent if they give the same answer for every instance of the database. Consider the following database: [15 points]
government(name, rank, salary) politician(name, party, gender) donation(name, organization, amount)
For each of the following five pairs of SQL queries, determine whether they are equivalent. If they are not, give a database instance as a counter-example. Otherwise, just state that they are equivalent.
o select name from donation A where not exists (select * from donation B where name = 'Campbell' and not exists (select * from donation C where C.organization = B.organization and C.name = A.name)) o select name from donation A where not exists (select * from donation where name = 'Campbell' and organization not in (select organization from donation B where B.name = A.name))
Yes, they are equivalent.
o (select name from government where salary >= 100000) union (select name from government where salary < 100000)
Charlie 150000
Don 50000
Then, the first query returns Albert, Charlie; but the second query returns empty set
o select name from politician where name not in (select name from government) o select name from politician where not exists (select * from government where government.name = politician.name)
Yes, they are equivalent.
o select name from politician where name not in (select name from government) o select politician.name from politician, government where not politician.name = government.name
No, a counterexample is:
politician relation
name
Albert
Charlie
government relation
name
Albert
Bobbie
Then, the first query returns Charlie but the second query returns Albert and Charlie
(B) Consider the following relations: [35 points]
Student ( snum , sname, major, level, age) Class ( name , meets_at, room, fid) Enrolled ( snum, cname ) Faculty ( fid , fname, deptid)
Write the following queries in SQL. Eliminate duplicates, and explicitly specify the keys for join operations.