In: Computer Science
Consider the following database schema:
LIKE(person, sport),
PRACTICE(person, sport),
where person and sport are keys in both tables. The table LIKE
gives the sports a person likes, the table PRACTICE gives the
sports a person practices. We assume that a person likes at least
one sport and practices at least one sport. We assume also that a
person does not like a sport if the sport is not listed among the
sports that a person likes
Express the following queries in Calculus
List the people who practice at list one sport they like
List the people who practice at least one sport they do not
like
List pairs of people who practice at least one common sport
List the people who like all the sports they practice
List the people who practice all the sports they like
List the people who practice all the sports John likes
1.
LIKE.person
LIKE.person = PRACTICE.person ^ LIKE.sport = PRACTICE.sport (LIKE
X PRACTICE)
2.
person ( (PRACTICE) - (LIKE) )
3.
a.person, b.person
a.sport = b.sport ^ a.person != b.person (PRACTICE a X PRACTICE
b)
// self join practice where sport is same but people
different
4.
person ( (PRACTICE)
(LIKE) )
// whatever they practice is a subset of sports they Like
5.
person ( (LIKE)
(PRACTICE) )
// whatever they like is a subset of sports they Practice
6.
person ( (PRACTICE)
((
sport (LIKE) )
(
sport (PRACTICE)) ) )
// Practice relation is divided by all the sports in the union of
Like and Practice
i hope it helps..
If you have any doubts please comment and please don't dislike.
PLEASE GIVE ME A LIKE. ITS VERY IMPORTANT FOR ME