-1

我有两个关系

Author (authorId, authorName, country)

PrizeWinner (mAuthId, fAuthId, year)

在哪里:

fk(mAuthId) -> authorId of Author 
fk(fAuthId) -> authorId of Author

PrizeWinner 表包含在给定年份获得最佳作者奖的男性和女性对的 ID。

当男性 (mAuthID) 和女性作者 (fAuthId) 来自同一个国家时,我们需要列出所有获奖作者对

对此的任何帮助或线索将不胜感激。谢谢你。

4

1 回答 1

1
SELECT male.*, female.*
FROM 
    PrizeWinner p
        INNER JOIN Author male ON male.authorId = p.mAuthId
        INNER JOIN Author female ON female.authorId = p.fmAuthId
WHERE
    male.country = female.country

关于你的评论,试试这个:

SELECT DISTINCT all.authorName, all.country
FROM 
    PrizeWinner p
        INNER JOIN Author male ON male.authorId = p.mAuthId
        INNER JOIN Author female ON female.authorId = p.fmAuthId
        INNER JOIN Author all ON all.authorId = male.authorId OR all.authorId = female.authorId
WHERE
    male.country = female.country
于 2013-02-17T18:55:27.907 回答