我的DataBase中有三个表名为Equipe(团队),Match(Match),Jouer(Played),我试图用这个来显示联盟的结果:
SELECT DISTINCT M.ID_MATCH, NOM_EQUIPE, BUT_MARQUE
FROM EQUIPE AS E, JOUER AS J, [MATCH] AS M
WHERE E.ID_EQUIPE = J.ID_EQUIPE and J.ID_MATCH = M.ID_MATCH
ORDER BY M.ID_MATCH;
,表格如下:
EQUIPE:
匹配度:
它们与tabble JOUER相关:
问题是,我得到的结果如下:
有没有办法让结果更像
ID_MATCH , Team1 , result1 , Team2 , result2
答案 0 :(得分:1)
SELECT M.ID_MATCH, E1.NOM_EQUIPE, J1.BUT_MARQUE, E2.NOM_EQUIPE, J2.BUT_MARQUE
FROM JOUER AS J1
INNER JOIN JOUER AS J2 ON J2.ID_MATCH = J1.ID_MATCH and J2.ID_EQUIPE > J1.ID_EQUIPE
INNER JOIN [MATCH] AS M ON J1.ID_MATCH = M.ID_MATCH
INNER JOIN EQUIPE AS E1 ON E1.ID_EQUIPE = J1.ID_EQUIPE
INNER JOIN EQUIPE AS E2 ON E2.ID_EQUIPE = J2.ID_EQUIPE
ORDER BY M.ID_MATCH;
诀窍是在ID_MATCH上加入JOUER,但也只有在J2.ID_EQUIPE> J1.ID_EQUIPE。这样你只能获得1个团队组合而不是4个团队。
我希望这会有所帮助。 Bonne Chance!