简体   繁体   English

列出出现“哈里森福特”的电影

[英]List the films in which 'Harrison Ford' has appeared

Why is the answer to this question incorrect?为什么这个问题的答案不正确?

Database数据库

movie (id(PK),  title,  yr,     director(FK),   budget,     gross)
actor (id(PK),  name )
casting (movieid(PK, FK),   actorid(PK, FK),    ord)

Question: List the films in which 'Harrison Ford' has appeared (original link here )问题:列出出现“哈里森福特”的电影( 此处为原始链接)

My answer:我的答案:

select title
from movie
were id IN
(
    select movieid as id
    from casting
    where actorid IN 
    (
        select id as actorid
        from actor
        where name = 'Harrison Ford'
    )
) X

After correcting were -> where and removing the trailing X the syntax and result where correct.更正后were -> where并删除尾随的X语法和结果正确的地方。

select title
from movie
where id IN
(
    select movieid as id
    from casting
    where actorid IN 
    (
        select id as actorid
        from actor
        where name = 'Harrison Ford'
    )
)

Error message indicated it was using MariaDB错误消息表明它正在使用 MariaDB

    select title from movie inner join casting on (movie.id = casting.movieid)
    inner join actor on (casting.actorid = actor.id)
    where actor.name = 'Harrison Ford'

Please use the above SQL code for this question on SQL Zoo;请在 SQL Zoo 上使用上面的 SQL 代码解决这个问题; it is in the exercise related to "More Joins".它在与“更多连接”相关的练习中。 Hence you should be using Joins to solve it因此你应该使用 Joins 来解决它

My solution using CTE and JOIN :我使用 CTE 和JOIN的解决方案:

-- find the movieid in which Harrison Ford played
WITH t AS (
    SELECT DISTINCT movieid
    FROM actor
    JOIN casting ON actor.id = casting.actorid
    WHERE name = 'Harrison Ford'
)

-- Get the movie title using a simple inner join
SELECT title
FROM movie
JOIN t ON movie.id = t.movieid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM