Here DIFFERENCE is the set difference operator extended to work with any two pairs of relations. This extended DIFFERENCE is generally called an ANTIJOIN, you can look up its definition here



Question 1: Where and when can we see the movie “Mad Max...”?
Solution 1: DROP(FILTER(Room,movieTitle="Mad Max"),MovieTitle)


Question 2: What are the movies directed by Welles?
Solution 2: DROP(DROP(FILTER(Movie,Director="Welles"), Director), Actor)

Question 3:
Who are the actors of "Ran"?
Solution 3: DROP(DROP(FILTER(Movie,MovieTitle="Ran"),Director),MovieTitle)

Question 4: Where can we see a movie in which Signoret plays?
Solution 4:
    moviesWithS = DROP(DROP(FILTER(Movie,Actor="Signoret"),Actor),Director)
    whereMovie = RENAME(DROP(Movie,Time),MovieTitle,MovieTitleBis)
    DROP(FILTER(PRODUCT(moviesWithS,whereMovie), movieTitle=movieTitleBis),            [MovieTitle,MovieTitleBis])


Question 5: Among the actors who produced at least one movie?
Solution 5:
    actors = DROP(DROP(Movie,MovieTitle),Director)
    producers = DROP(Producers,MovieTitle)
    DROP(FILTER(PRODUCT(actors,producers),ProducerName=Actor),ProducerName)
   
Question 6:
Among the actors who directed a movie that they played in?
Solution 6:
    DROP(FILTER(Movie,Director=Actor),[MovieTitle,Director])
   
Question 7: Who plays in one (or more) movie from Varda?
Solution 7: DROP(FILTER(Movie,Director="Varda"),[MovieTitle,Director])


Question 8: Who are the actors playing in all the films from Chloé Zhao?
Solution 8:
    ZhaoMovies = DROP(FILTER(Movie,Director="Zhao"),[Director,Actor])
    allPairsA_ZM = PRODUCT(actors,ZhaoMovies)
    missingPairs = DIFFERENCE(allPairsA_ZM,Movie)
    actorsInAllZhao = DIFFERENCE(actors,missingPairs)
   
Question 9:
Who produces all the movies from Kurosawa?
Solution 9:
    KurosawaMovies = DROP(FILTER(Movie,Director="Kurosawa"),[Director,Actor])
    AllPairsKM_P = PRODUCT(producers,KurosawaMovies)
    missingPairs = DIFFERENCE(Producer,AllPairsKM_P)
    producersNotInAllK = DIFFERENCE(Producer,missingPairs)
    DIFFERENCE(Producer,producersNotInAllK)
   
Question 10:
Who are the spectators watching all the movies?
Solution 10:
    movieNames = DROP(Movie,[Director,Actor])
    spectators = DROP(Seen,MovieTitle)
    allPairs_ms = PRODUCT(movieNames,spectators)
    missingPairs = DIFFERENCE(allPairs_ms, Seen)
    DIFFERENCE(spectators, missingPairs)
   
Question 11:
Among the spectators, who likes all the movies they see?
Solution 11:
    DIFFERENCE(Seen,DIFFERENCE(Seen,Like))
   

Question 12:
Where can we see Adèle Haenel after 16:00?
Solution 12:
    moviesRoomAfter16 = DROP(FILTER(Room,time>=16:00),Time)
    moviesWithHaenel = RENAME(DROP(FILTER(Movie,Actor=Haenel),[Director,Actor]),MovieTitle,MovieTitleBis)
    DROP(FILTER(PRODUCT(moviesRoomAfter16,moviesWithHaenel),movieTitle=movieTitleBis),[movieTitle,movieTitleBis])
   
Question 13:
What are the movies with no room projecting them?
Solution 13: DIFFERENCE(Movie,Rooms)
   
   
Question 14:
Among the producers, who produces a movies shown nowhere?
Solution 14:
    DIFFERENCE(Producer,Room)
   
Question 15:
Among the producers who saw all the movies they directed?
Solution 15:
    AllPairs_P_M = PRODUCT(movieNames, producers)
    missingPairs = DIFFERENCE(AllPairs_P_M,Producer)
    DIFFERENCE(producers,missingPairs)
   
Question 16:
Among the spectators, who saw all the movies from Kurosawa
Solution 16:
    moviesK = DROP(FILTER(Movie,Director="Kurosawa"),[Director,Actor])
    allPairs_ms = PRODUCT(moviesK,spectators)
    missingPairs = DIFFERENCE(allPairs_ms, Seen)
    DIFFERENCE(spectators, missingPairs)

Question 17:
Among the spectators, who liked a movie they did not watch?
Solution 17:
    DROP(DIFFERENCE(Like,Seen),MovieTitle)
   
Question 18:
Among the spectators, who liked 0 movies?

Solution 18:  DIFFERENCE(DROP(Seen,MovieTitle),DROP(Like,MovieTitle))
   
   

Last modified: Friday, 16 September 2022, 5:01 PM