CS50 Pset 7 13.sql, I can't solve it, nested sqlite3 database

后端 未结 5 888
感动是毒
感动是毒 2020-12-11 14:10

DataBase movies.db

tables

directors (movie_id, person_id)

movies (id, title, year)

people

5条回答
  •  暖寄归人
    2020-12-11 14:31

    I solved this problem by using DISTINCT and NOT EQUAL operator in SQL.

    Here are the steps I took:

    SELECT DISTINCT(name)
    FROM people
    JOIN stars ON stars.person_id = people.id
    JOIN movies ON movies.id = stars.movie_id
    WHERE movies.id IN
        (SELECT movie_id
         FROM movies
         JOIN stars ON stars.movie_id = movies.id
         JOIN people ON people.id = stars.person_id
         WHERE people.name = "Kevin Bacon"
           AND people.birth = 1958)
      AND people.name != "Kevin Bacon";
    

    Result is 176 distinct rows of names.

提交回复
热议问题