आइए इसे चरण दर चरण करते हैं:
घर पर जीते गए गेम और घर पर स्कोर चुनें:
SELECT COUNT(*) as wins, SUM(G.home_score) as score FROM games G WHERE
G.team_id = T.team_id #See 3. query and you'll understand
G.home_score > away_score
आइए इस परिणाम को HOME_GAMES कहते हैं।
जीते गए गेम और अवे गेम के स्कोर का चयन करें:
SELECT COUNT(*) as wins, SUM(G.away_score) as score FROM games G
WHERE
G.team_id = T.team_id #See 3. query and you'll understand
G.away_score > G.home_score
आइए इस परिणाम को AWAY_GAMES कहते हैं।
जीते गए कुल गेम और कुल स्कोर चुनें:
SELECT (A.wins + H.wins) AS total_wins, (A.score + H.score) AS total_score FROM
(AWAY_GAMES) AS A, (HOME_GAMES) AS H, teams T
ORDER BY total_wins, total_score
==> AWAY_GAMES और HOME_GAMES को प्रतिस्थापित करके सभी को एक साथ रखें:
SELECT (A.wins + H.wins) AS total_wins, (A.score + H.score) AS total_score FROM
(SELECT COUNT(*) as wins, SUM(G.away_score) as score FROM games G
WHERE
G.team_id = T.team_id #See 3. and you'll understand
G.away_score > G.home_score) AS A,
(SELECT COUNT(*) as wins, SUM(G.home_score) as score FROM games G
WHERE
G.team_id = T.team_id #See 3. and you'll understand
G.home_score > away_score) AS H,
teams T
ORDER BY total_wins, total_score