大家好!有一个表仅包含3列(“ playerID”,“ teamID”和“ yearID”)

我只想获得在同一球员的同一年和同一支球队中的列。您可以看到以下代码:

Select playerID, teamID, yearID
FROM `appearancessmall`
WHERE (teamID IN
(SELECT teamID from  `appearancessmall` WHERE playerID = 'napolmi01' )
) AND
(yearID  IN (SELECT yearID from  `appearancessmall` WHERE playerID =
'napolmi01')
)


但是查询的输出是与玩家“ napolmi01”具有相同teamID或相同yearID的总列,我要选择的列应同时满足这两个要求。那么该怎么做呢?

最佳答案

尝试合并两个子查询并同时比较两个列:

SELECT
   playerID
 , teamID
 , yearID
FROM `appearancessmall`
WHERE
  (teamID,yearID) IN (
   SELECT teamID,yearID
   FROM `appearancessmall`
   WHERE playerID = 'napolmi01'
   )

关于mysql - 选择一个与另一列具有相同属性的列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47734646/

10-13 00:09