從match
表獲取行。如果你不知道,如果是TEAM1利物浦阿森納或者,或TEAM2
SELECT m.matchid
FROM match m
WHERE m.date = TO_DATE('2016-03-28','YYYY-MM-DD')
AND m.team1 IN ('Liverpool','Arsenal')
AND m.team2 IN ('Liverpool','Arsenal')
AND m.team1 <> m.team2
接下來,使該行的兩個副本,反之亦然......
SELECT m.matchid
FROM (SELECT 1 AS i UNION ALL SELECT 2) d
CROSS
JOIN match m
WHERE m.date = TO_DATE('2016-03-28','YYYY-MM-DD')
AND m.team1 IN ('Liverpool','Arsenal')
AND m.team2 IN ('Liverpool','Arsenal')
AND m.team1 <> m.team2
的執行加盟的球員表,看起來像我們使用teamname列匹配。
SELECT CASE WHEN d.i = 1 THEN m.team1 ELSE m.team2 END AS teamname
, p.playername
FROM (SELECT 1 AS i UNION ALL SELECT 2) d
JOIN match m
ON m.date = TO_DATE('2016-03-28','YYYY-MM-DD')
AND m.team1 IN ('Liverpool','Arsenal')
AND m.team2 IN ('Liverpool','Arsenal')
AND m.team1 <> m.team2
LEFT
JOIN players p
ON p.teamname IN (m.team1, m.team2)
ORDER BY d.i, p.playerid
已格式化的文章。問題仍然是質量很低,OP應該嘗試編輯並更詳細地介紹迄今爲止已有的查詢。 –
刪除謝謝。 –