sql在国家表,对战表,进球表里查询请查询 D 组各场比赛的进球数。进球数为 0 时也要显示。 显示项目:开球时间、本国名、对战国名、本国的进球数、对战国的进球数、进球数差 显示顺序:开球时间的升序、本国的 FIFA 排名的升序
时间: 2024-05-20 11:17:42 浏览: 125
SELECT m.kickoff_time, t1.country_name AS home_country, t2.country_name AS away_country,
COALESCE(hg.home_goals, 0) AS home_goals, COALESCE(ag.away_goals, 0) AS away_goals,
COALESCE(hg.home_goals, 0) - COALESCE(ag.away_goals, 0) AS goal_diff
FROM matches m
JOIN countries t1 ON m.home_team = t1.country_id
JOIN countries t2 ON m.away_team = t2.country_id
LEFT JOIN (SELECT match_id, home_goals FROM goals) hg ON m.match_id = hg.match_id AND m.home_team = hg.country_id
LEFT JOIN (SELECT match_id, away_goals FROM goals) ag ON m.match_id = ag.match_id AND m.away_team = ag.country_id
WHERE m.group_id = 'D'
ORDER BY m.kickoff_time ASC, t1.fifa_ranking ASC;
阅读全文