题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
WITHt1AS(SELECThost_teamteam_id, SUM(IF(host_goals=guest_goals, 1, IF(host_goals>guest_goals, 3, 0))) pointsFROMMatchesGROUPBYhost_teamUNIONALLSELECTguest_teamteam_id, SUM(IF(host_goals=guest_goals, 1, IF(host_goals<guest_goals, 3, 0))) pointsFROMMatchesGROUPBYguest_team) SELECTt.team_id, team_name, SUM(IFNULL(points, 0)) num_pointsFROMt1RIGHTJOINTeamstONt.team_id=t1.team_idGROUPBYteam_idORDERBYnum_pointsDESC, team_id