You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ibihf/migrations/20230406195111_create_ot_wi...

20 lines
464 B

CREATE FUNCTION ot_win(game_id INT, team_id INT)
RETURNS INTEGER
AS $$
DECLARE
opponent_team_id INTEGER;
BEGIN
SELECT
teams.id
INTO
opponent_team_id
FROM games
JOIN teams
ON (teams.id=games.team_home
OR teams.id=games.team_away)
WHERE games.id=game_id
AND teams.id!=team_id;
RETURN (SELECT (CASE WHEN goals(game_id, team_id) < goals(game_id, opponent_team_id) AND periods(game_id) > 3 THEN 1 ELSE 0 END));
END;
$$ LANGUAGE plpgsql;