为了扩展我之前的问题 - 我的数据库中有两个表,我想提取某些信息。表格如下:
(player): player_id (primary), playerName
(match): match_id (primary), playerID1, playerID2, playerID3, scorer etc..
您向我提供了以下代码以获取玩家的姓名:
SELECT p.Name
FROM `match` m
INNER JOIN `player` p
ON p.player_id IN (m.playerID1, m.playerID2, m.playerID3) //etc
非常感谢 - 我只想进行两项调整:
答案 0 :(得分:3)
尝试以下内容(假设字段名称)。它会显示玩家的名字,匹配的matchId以及他们是否在该比赛中得分:)。
SELECT p.Name as 'Player Name', m.matchId as 'Match Id',
CASE s.scorerId WHEN ISNULL(S.SCORERID,0) THEN 'YES' ELSE 'NO' END as 'Scored?',
s.name as 'Scorer Name' --as requested from comment
FROM match m
INNER JOIN player p ON p.player_id IN (m.playerID1, m.playerID2, m.playerID3)
LEFT JOIN scorer s ON s.matchId = m.matchId
AND s.player_id IN (m.playerID1, m.playerID2, m.playerID3)
请参阅此SQLFiddle HERE