(20 points) Consider the following example instance of the
AKnowsB relation: it is a veritable list of who-knows-who.
------------------------------------
this person knows | this other person
------------------------------------
(Little Jimmy | Bill Clinton)
(Tommy Hanks | Bill Clinton)
(Bill Clinton | Bill Clinton)
(Tommy Hanks | Kofi Annan)
(Little Jimmy | Kofi Annan)
(Bill Clinton | Kofi Annan)
(Kofi Annan | Bill Clinton)
(Tommy Hanks | Little Jimmy)
------------------------------------
Thus, the data means that Little Jimmy knows Bill Clinton, Tommy Hanks
knows Bill Clinton and so on. Notice that sometimes people are listed as
knowing themselves. For example, Bill Clinton knows Bill Clinton. Sometimes
they are not listed like this (like Kofi Annan doesn't seem to know himself).
A celebrity is defined as somebody who is known by everybody other than
himself/herself. So, Bill Clinton is an example of a celebrity since he is
known by everybody else (Little Jimmy, Tommy Hanks, and Kofi Annan). Kofi
Annan is also a celebrity since he is known by everybody else (Little Jimmy,
Tommy Hanks, and Bill Clinton). Never mind that he doesn't know himself (that
is not involved in the definition of a celebrity). But Little Jimmy is not
a celebrity since he is known only by Tommy Hanks.
Write a query in SQL (using only constructs given in Sections 6.1 and
6.2 and perhaps VIEWS) to find all the celebrities in a given
instance of AKnowsB. Be careful about the condition when some people
are listed as knowing themselves and some are not listed as knowing
themselves (we don't know in advance who these people are).
The above is just example data; your query should work for all possible
inputs.
Also, we are only looking at "direct knowings". So, if P1 knows P2 and
P2 knows P3, this doesn't mean that P1 knows P3 (unless this is
listed separately).
FAQ: Is there a master list of "all people" that I can use as
a reference?
Answer: Not really. You can take apart the two columns of the
AKnowsB relation and union them together to get a master list.
FAQ: You say that a celebrity is somebody who is known by everybody
other than himself (or herself). So, the definition of the celebrity would be
different for everybody (for Bill Clinton, it means "known by everybody other than
Bill Clinton"; for Little Jimmy, it means "known by everybody other than
Little Jimmy", and so on). How can we express this in SQL? Do we
have to write different constructs for each person?
Answer: You don't need to and you shouldn't. There is a way to write the query so that it
works for everybody, without hardwiring the names of anybody.