Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

mysql - SHAHRUKH KHAN question SQL query on IMDB data set

Q; The Shahrukh number of an actor is the length of the shortest path between the actor and Shahrukh Khan in the "co-acting" graph. That is, Shahrukh Khan has Shahrukh number 0; all actors who acted in the same film as Shahrukh have Shahrukh number 1; all actors who acted in the same film as some actor with Shahrukh number 1 have Shahrukh number 2, etc. Return all actors whose Shahrukh number is 2

query9 ="""WITH SHAHRUKH_0
AS
    (
        SELECT
            TRIM(P.PID) PID
        FROM
            Person P
        WHERE
            Trim(P.NAME) = "Shah Rukh Khan"
    )
, SHAHRUKH_1_MOVIES
AS
    (
        SELECT DISTINCT
            TRIM(MC.MID) MID
            , S0.PID
        FROM
            M_Cast MC
            , SHAHRUKH_0 S0
        WHERE
            TRIM(MC.PID) = S0.PID
    )
, SHAHRUKH_1_ACTORS
AS
    (
        SELECT DISTINCT
            TRIM(MC.PID) PID
        FROM
            M_Cast MC
            , SHAHRUKH_1_MOVIES S1M
        WHERE
            TRIM(MC.MID) = S1M.MID
            AND TRIM(MC.PID) <> S1M.PID
    )
, SHAHRUKH_2_MOVIES
AS
    (
        SELECT DISTINCT
            TRIM(MC.MID) MID
            , S1A.PID
        FROM
            M_Cast MC
            , SHAHRUKH_1_ACTORS S1A
        WHERE
            TRIM(MC.PID) = S1A.PID
    )
SELECT DISTINCT
    TRIM(P.Name) ACTOR_NAME
FROM
    Person P
    , M_Cast MC
    , SHAHRUKH_2_MOVIES S2M
WHERE
    TRIM(MC.PID) = TRIM(P.PID)
    AND TRIM(MC.MID) = S2M.MID
    AND TRIM(MC.PID) != S2M.PID;"""

Total s2 actors are 25698 but i am getting 26521. please suggest.

question from:https://stackoverflow.com/questions/65886735/shahrukh-khan-question-sql-query-on-imdb-data-set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...