获取所有获得超过一枚奖牌的球员的姓名。
(不清楚这意味着什么。赢得了不止一种奖牌?还是获得了不止一种奖牌?您的示例答案建议后者。此外,它把“null”视为另一种奖牌,而不是特别像 SQL .)
-- rows where
THERE EXISTS compId,sport,medal,compId1,compId2,medal2 SUCH THAT
in competition [compId] of sport [sport] player [playerName] won [medal]
AND in competition [compId2] of sport [sport2] player [playerName] won [medal2]
AND (compId <> compId2 OR sport <> sport2 OR medal <> medal2)
使用语句速记:
-- rows where
THERE EXISTS compId,sport,medal,compId1,compId2,medal2 SUCH THAT
Competition(compId, sport, playerName, medal)
AND Competition(compId2, sport2, playerName, medal2)
AND (compId <> compId2 OR sport <> sport2 OR medal <> medal2)
重新排列(预计每个 σ 一个比较和每个 ∪ 一个属性集的限制):
-- rows where
THERE EXISTS compId,sport,medal,compId1,compId2,medal2 SUCH THAT
( Competition(compId, sport, playerName, medal)
AND Competition(compId2, sport2, playerName, medal2)
AND compId <> compId2)
OR ( Competition(compId, sport, playerName, medal)
AND Competition(compId2, sport2, playerName, medal2)
AND sport <> sport2)
OR ( Competition(compId, sport, playerName, medal)
AND Competition(compId2, sport2, playerName, medal2)
AND medal <> medal2)
现在得到代数替换:
(有关更多信息,请参阅此答案。)