SELECT t.team_name, t.team_id
FROM tdg_team t,
(SELECT r.team_id, rank() over (PARTITION BY r.team_group_id ORDER BY r.points DESC, r.matches_won DESC, r.goals_difference DESC, r.goals_scored DESC) team_rank
FROM tdg_match_rank r
WHERE r.tournament_id = :TDG_AI_TOURNAMENT_ID) rt
WHERE t.team_id = rt.team_id AND rt.team_rank IN (1,2)
A statement with the pre-tag:
SELECT t.team_name, t.team_id
FROM tdg_team t,
(SELECT r.team_id, rank() over (PARTITION BY r.team_group_id
ORDER BY r.points DESC, r.matches_won DESC,
r.goals_difference DESC, r.goals_scored DESC) team_rank
FROM tdg_match_rank r
WHERE r.tournament_id = :TDG_AI_TOURNAMENT_ID) rt
WHERE t.team_id = rt.team_id
AND rt.team_rank IN (1,2)
No comments:
Post a Comment