Query Library

Casey Trauer submitted this query on: February 13, 2012 11:04am EST
TITLE Basketball season offensive stats for team
SPORTS Basketball
QUERY SELECT dn_team.first_name, dn_player.first_name, dn_player.last_name, p.person_key, off.field_goals_made FG, off.field_goals_attempted FGA, off.three_pointers_made 3G, off.three_pointers_attempted 3GA, free_throws_made FT, free_throws_attempted FTA, off.points_scored_total PTS, off.assists_total AST, off.turnovers_total 'TO'

FROM stats AS s
JOIN sub_seasons ss ON (s.stat_coverage_type = 'sub_seasons' AND s.stat_coverage_id=ss.id)
JOIN basketball_offensive_stats off ON (s.stat_repository_id = off.id AND s.stat_repository_type = 'basketball_offensive_stats')
JOIN display_names dn_player ON (dn_player.entity_id = s.stat_holder_id AND dn_player.entity_type = 'persons' AND s.stat_holder_type = 'persons')
JOIN display_names dn_team ON (dn_team.entity_id = s.stat_membership_id AND dn_team.entity_type = 'teams' AND s.stat_membership_type = 'teams')
JOIN persons p ON s.stat_holder_id = p.id
JOIN teams t ON s.stat_membership_id = t.id
JOIN seasons ON ss.season_id = seasons.id
JOIN publishers pub ON seasons.publisher_id = pub.id

WHERE pub.publisher_key = 'sportsnetwork.com'
AND ss.sub_season_key = '2011_season_regular'
AND t.team_key = 'l.nba.com-t.1'

ORDER BY off.points_scored_total+1 DESC
DESCRIPTION Returns cumulative season offensive stats for each player on a team.
DBs TESTED MySQL
ADDITIONAL NOTES