我需要查询帮助。您将获得表:player(playerID(主键),playerName)和village(villageID,villageName,x,y,population,playerID(外键)并检查y中的x是否介于-400和400之间)。
任务是编写一个查询,其输出是玩家名称,他们的所有村庄在x上都是100到200之间,y上是0到100。
目前我有这个查询,但它并没有找到所有的村庄。
SELECT i.playerName
FROM player i JOIN
village n
USING(playerID)
WHERE (n.x BETWEEN 100 AND 200) AND (n.y BETWEEN 0 AND 100);
答案 0 :(得分:0)
如果您想要所有村庄,那么您需要比较所有行。这表明聚合:
SELECT i.playerName
FROM igralec i JOIN
naselje n
USING (playerID)
GROUP BY i.playerName
HAVING SUM( (n.x BETWEEN 100 AND 200) AND (n.y BETWEEN 0 AND 100) ) = COUNT(*);
HAVING
子句保证所有行(即城市)符合给定玩家的条件。