大家好!有一个表只包含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的总列,我想要的是选择的列应同时满足两个要求。那怎么办?
答案 0 :(得分:0)
尝试使用以下示例中的LEFT JOIN
SELECT `et`.* FROM `test` `t`
LEFT JOIN `test` `et`
ON `t`.`teamID`=`et`.`teamID` AND `t`.`yearID`=`et`.`yearID`
WHERE `t`.`playerID`='napolmi01';
上试用
答案 1 :(得分:-1)
尝试组合2个子查询并同时比较两个列:
SELECT
playerID
, teamID
, yearID
FROM `appearancessmall`
WHERE
(teamID,yearID) IN (
SELECT teamID,yearID
FROM `appearancessmall`
WHERE playerID = 'napolmi01'
)