【发布时间】:2016-04-08 09:38:07
【问题描述】:
查看下表。
表spawns:
+----------+---+----+----+--+
| id_spawn | position | map |
+----------+---+----+----+--+
| 1 | 1 | 1 |
| 2 | 2 | 1 |
+----------+----------+-----+
表games;
+---------+-----+
| id_game | map |
+---------+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
+---------+-----+
表warriors:
+---------+------+----------+
| id_join | game | position |
+---------+------+----------+
| 1 | 1 | 2 |
+---------+------+----------+
我正在尝试从spawns 中获取尚未在warriors 中使用的position,并给出特定的game。第一次尝试我做了:
select s.position
from spawns s
left join games g on g.map = s.map
left join warriors w on w.game = g.id_game
where s.position not in(w.position)
and g.id_game = 1;
查询按预期返回
1
但是,对于game = 5,我期待有 2 个可用职位,但收到的结果为空。我假设数据库引擎没有找到games 和warriors 之间的关系,因为游戏没有战士可以比较。那么,我怎样才能获得这些职位呢?
【问题讨论】:
-
也许我遗漏了什么,但我没有在表格中看到
s.game? -
谢谢。抄写的时候弄错了。
标签: mysql