(d) One of the ways is to first get all of the recursive tuples as for the original
FollowOn in (a), and then subtract the those tuples that represent sequel or
sequel of a sequel. Using the book’s syntax, the SQL would be:
WITH RECURSIVE FollowOn(movie, followOn) AS
(SELECT movie, sequel
FROM SequelOf )
UNION
(SELECT F.movie, S.sequel
FROM FollowOn F, Sequel S
Another way would be to start FollowOn tuples only from the tuples of
movies that have more than two sequels (using a join similar to the one
above but with three Sequel tables).
(e) We simply need to count the number of followon values per movie. Using
the book’s syntax, the SQL would be:
WITH RECURSIVE FollowOn(movie, followOn) AS
7