turbot/nba

Query: nba_home_away_wins_by_team

Usage

powerpipe query nba.query.nba_home_away_wins_by_team

SQL

with home_wins as (
select
team_id_home as team_id,
count(*) as home_wins
from
game
where
wl_home = 'W'
group by
team_id_home
),
away_wins as (
select
team_id_away as team_id,
count(*) as away_wins
from
game
where
wl_away = 'W'
group by
team_id_away
)
select
t.full_name,
h.home_wins,
a.away_wins
from
home_wins h
join away_wins a on h.team_id = a.team_id
left join team t on h.team_id = t.id
order by
a.away_wins, h.home_wins desc;

Dashboards

The query is used in the dashboards: