有两张桌子可以追踪棒球运动员及其位置。
播放器
+----+----------
| id | name
+----+----------
| 1 | Boggs
| 2 | Mattingly
| 3 | Judge
| 4 | Martinez
| 5 | Rodriguez位置
+----+----------+-----------+
| id | player_id | position
+----+----------+-----------+
| 1 | 1 | Pitcher
| 2 | 1 | Third Base
| 3 | 2 | First Base
| 4 | 3 | Second Base
| 5 | 3 | Pitcher 所以博格斯是一个投手,打第三垒,而马塔利只打第一页,而裁判是一个皮瑟和二垒手。
在MySQL中是否有一种方法可以只让那些不是投手的球员上场?因此,这个样本的结果应该是非常重要的。
我当然做不到..。
select id from Player where id not in (select player_id from Position where position = 'Pitcher')因为博格斯和法官会有好感的回报。
发布于 2018-03-13 17:27:55
select p.* from player p
join position pn on p.id = pn.player_id
where pn.position not in ('Pitcher')发布于 2018-03-13 17:27:37
你试过:
select id from Player where id not in
(select player_id from Position WHERE position = 'Pitcher')发布于 2018-03-13 17:43:29
您需要将表名从'Position'更改为'Positions',因为它不应该具有与列名相同的名称。一旦完成,您应该能够在上面的答案中使用查询。
select id from Player where id not in
(select player_id from Position WHERE position = 'Pitcher')https://stackoverflow.com/questions/49262265
复制相似问题