sqlite 我在cs50 pset 7 10.sql嵌套查询中哪里出错了?

6rqinv9w  于 2023-05-23  发布在  SQLite
关注(0)|答案(2)|浏览(140)

我目前正试图找到所有人的名字谁导演的电影,收到了至少9.0的评级方案,这些表是

CREATE TABLE movies (

                    id INTEGER,
                    title TEXT NOT NULL,
                    year NUMERIC,
                    PRIMARY KEY(id)
                );
CREATE TABLE stars (

                movie_id INTEGER NOT NULL,
                person_id INTEGER NOT NULL,
                FOREIGN KEY(movie_id) REFERENCES movies(id),
                FOREIGN KEY(person_id) REFERENCES people(id)
            );
CREATE TABLE directors (

                movie_id INTEGER NOT NULL,
                person_id INTEGER NOT NULL,
                FOREIGN KEY(movie_id) REFERENCES movies(id),
                FOREIGN KEY(person_id) REFERENCES people(id)
            );
CREATE TABLE ratings (

                movie_id INTEGER NOT NULL,
                rating REAL NOT NULL,
                votes INTEGER NOT NULL,
                FOREIGN KEY(movie_id) REFERENCES movies(id)
            );
CREATE TABLE people (

                id INTEGER,
                name TEXT NOT NULL,
                birth NUMERIC,
                PRIMARY KEY(id)
            );

我的SQL查询是:

SELECT DISTINCT name FROM people 
WHERE id IN ( SELECT person_id FROM directors WHERE movie_id IN ( 
    SELECT id FROM movies WHERE id IN (
        SELECT movie_id FROM ratings WHERE votes >= 9.0)));

然而,这使check50测试失败,并且给出不正确的输出。谁能帮我看看我哪里做错了?

rsaldnfx

rsaldnfx1#

说明书上说(强调部分由作者补充)
10.sql中,编写一个SQL查询,列出所有执导过评分至少为9.0的电影的人的姓名。
查询不对ratings.rating列进行筛选。

yzxexxkh

yzxexxkh2#

试试这个:

select distinct name 
from directors 
join people on directors.person_id = people.id 
join ratings on directors.movie_id = ratings.movie_id 
where rating >= 9.0;

相关问题