Skip to content
Advertisement

Subquery error calculating Free throw statistics

trying to incorporate the query titled “free throws made” as a subquery into the query below it titled “FreeThrowPercByGame” but getting an error. Both work independent of each other in Google Big Query. Thank you.

--free throws made
  select  scheduled_date,
        home_market,
    away_market,
    team_name,
    count( *)FreeThrowMade,
    FROM
    `bigquery-public-data.ncaa_basketball.mbb_pbp_sr` gamestbl
    WHERE season IN (2017)
    AND (home_market IN ("Ohio State")
      OR away_market IN ("Ohio State"))
    AND event_type IN ("freethrowmade")
    AND period in (1,2)
    AND team_name IN ("Buckeyes")
    group by 
    scheduled_date,
        home_market,
    away_market,
    team_name
      ORDER BY
    scheduled_date asc


--FreeThrowPercByGame
    select
    scheduled_date,
    home_market,
    away_market,
    team_name,
    count(event_type IN ("freethrowmiss","freethrowmade"))NoOfFTAttempts
    FROM
    `bigquery-public-data.ncaa_basketball.mbb_pbp_sr` gamestbl
    WHERE
    season IN (2017)
    AND (home_market IN ("Ohio State")
      OR away_market IN ("Ohio State"))
    AND event_type IN ("freethrowmiss","freethrowmade")
    AND period in (1,2)
    AND team_name IN ("Buckeyes")
    group by 
    scheduled_date,
        home_market,
    away_market,
    team_name
      ORDER BY
    scheduled_date asc

Advertisement

Answer

Below is for BigQuery Standard SQL and is simple combining of your already working queries into one (working one)

#standardSQL
SELECT
  scheduled_date,
  home_market,
  away_market,
  team_name,
  COUNTIF(event_type = 'freethrowmade') FreeThrowMade,
  COUNT(1) NoOfFTAttempts
FROM `bigquery-public-data.ncaa_basketball.mbb_pbp_sr` gamestbl
WHERE season IN (2017)
AND (
  home_market IN ("Ohio State")
  OR away_market IN ("Ohio State")
  )
AND event_type IN ("freethrowmiss","freethrowmade")
AND period IN (1,2)
GROUP BY 
  scheduled_date,
  home_market,
  away_market,
  team_name
ORDER BY scheduled_date ASC
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement