Skip to content
Advertisement

Expecting Number (Average Temperature) but Getting Null [closed]

I want to pull the average temperature of two stations, JFK and La Guardia, for June 2020, but I am getting Null.

Here is my query:

SELECT
  AVG(temp) AS avg_temp
FROM
  bigquery-public-data.noaa_gsod.gsod2020
WHERE
  temp IN
 (
  SELECT
    AVG(temp)
  FROM
    bigquery-public-data.noaa_gsod.gsod2020
  WHERE
    stn="744860" -- JFK
   AND date BETWEEN '2020-06-01' AND '2020-06-30'
 ) 
 OR temp IN 
 (
  SELECT
    AVG(temp)
  FROM
    bigquery-public-data.noaa_gsod.gsod2020
  WHERE
    stn="725030" -- La Guardia
   AND date BETWEEN '2020-06-01' AND '2020-06-30'
 )
;

Advertisement

Answer

That SQL seems unnecessarily complicated, why not just use:

SELECT
    AVG(temp)
  FROM
    bigquery-public-data.noaa_gsod.gsod2020
  WHERE
   ( stn="744860" or stn="725030") 
   AND date BETWEEN '2020-06-01' AND '2020-06-30'
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement