{"ok": true, "database": "my_database", "query_name": "yoy_performance", "rows": [], "truncated": false, "columns": ["season_id", "season", "Points", "Games", "Wins", "Losses", "OTL", "SOL"], "query": {"sql": "with current_season_games as (\nselect count(*) as game_count\nfrom gamedata g\nleft join team ht on g.home_team_id = ht.team_id\nleft join team at on g.away_team_id = at.team_id\nleft join season s on g.season_id = s.season_id\nwhere s.end_date >= date('now')\nand s.career = 1\nand s.playoff = 0\nand (ht.name = :team or at.name = :team)\n),\ndata as (\nselect\ng.game_date\n, g.game_status\n, ht.name as home_team\n, g.home_team_score\n, at.name as away_team\n, g.away_team_score\n, s.season_name as season\n, s.season_id\n, s.end_date\n, row_number() over (partition by g.season_id order by g.game_date) as game_seq\n, case\nwhen\n(ht.name = :team and g.home_team_score > g.away_team_score) or (at.name = :team and g.home_team_score < g.away_team_score)\nthen\n   1\nelse\n   0\nend as 'W'\n, case\n   when g.game_status = 'Final' then\n   case\n      when (ht.name = :team and g.home_team_score < g.away_team_score) or (at.name = :team and g.home_team_score > g.away_team_score)\n      then 1\n      else 0\n   end\n   else 0\nend as 'L'\n, case\n   when g.game_status = 'Final OT' then\n   case\n      when (ht.name = :team and g.home_team_score < g.away_team_score) or (at.name = :team and g.home_team_score > g.away_team_score)\n      then 1\n      else 0\n   end\n   else 0\nend as 'OTL'\n, case\n   when g.game_status = 'Final SO' then\n   case\n      when (ht.name = :team and g.home_team_score < g.away_team_score) or (at.name = :team and g.home_team_score > g.away_team_score)\n      then 1\n      else 0\n   end\n   else 0\nend as 'SOL'\nfrom gamedata g\nleft join team ht on g.home_team_id = ht.team_id\nleft join team at on g.away_team_id = at.team_id\nleft join season s on g.season_id = s.season_id\nwhere (ht.name = :team or at.name = :team)\nand s.career = 1\nand s.playoff = 0\n)\nselect d.season_id\n, d.season\n, sum(2*W+OTL+SOL) as 'Points'\n, count(*) as 'Games'\n, sum(W) as 'Wins'\n, sum(L) as 'Losses'\n, sum(OTL) as 'OTL'\n, sum(SOL) as 'SOL'\nfrom data d\nwhere d.game_seq <= (select count(*) from gamedata g\n                     left join team ht on g.home_team_id = ht.team_id\n                     left join team at on g.away_team_id = at.team_id\n                     left join season s on g.season_id = s.season_id\n                     where s.end_date >= date('now')\n                     and s.career = 1\n                     and s.playoff = 0\n                     and (ht.name = :team or at.name = :team))\ngroup by d.season_id, d.season\norder by d.season_id desc\nlimit 2", "params": {"team": ""}}, "error": null, "private": false, "allow_execute_sql": true, "query_ms": 11.292489245533943}