使用 BigQuery 按月检索 AVG 温度?
Retrieve AVG Temp by Month using BigQuery?
使用 fh-bigquery:weather_gsod
数据集,我想检索特定国家/地区所有站点的一些月度天气数据。即,我想要从 1929 年到现在的每月平均温度、每月平均最大值和每月平均最小值。
这是我为了从一个 table 中检索我需要的东西而写的,2015 年。我得到的数据似乎是正确的:
SELECT stn, FIRST(name) AS station_name, mo, (AVG(temp)-32)*0.5556 AS temp, (AVG(max)-32)*0.5556 AS max, (AVG(min)-32)*0.5556 AS min
FROM [fh-bigquery:weather_gsod.gsod2015] gsod
JOIN [fh-bigquery:weather_gsod.stations2] stations
ON gsod.wban=stations.wban AND gsod.stn=stations.usaf
WHERE country='SA'
GROUP BY stn, mo
ORDER BY mo
假设这个查询确实检索到我需要的信息,我该如何重写它以便我可以包含整个范围(1929 到 2016)?
您应该使用 Table wildcard functions,如下所示
SELECT
stn,
FIRST(name) AS station_name,
mo,
(AVG(temp)-32)*0.5556 AS temp,
(AVG(max)-32)*0.5556 AS max,
(AVG(min)-32)*0.5556 AS min
FROM (
SELECT * FROM
(TABLE_QUERY([fh-bigquery:weather_gsod], 'table_id CONTAINS "gsod"'))
) gsod
JOIN [fh-bigquery:weather_gsod.stations2] stations
ON gsod.wban=stations.wban AND gsod.stn=stations.usaf
WHERE country='SA'
GROUP BY stn, mo
ORDER BY mo
使用 fh-bigquery:weather_gsod
数据集,我想检索特定国家/地区所有站点的一些月度天气数据。即,我想要从 1929 年到现在的每月平均温度、每月平均最大值和每月平均最小值。
这是我为了从一个 table 中检索我需要的东西而写的,2015 年。我得到的数据似乎是正确的:
SELECT stn, FIRST(name) AS station_name, mo, (AVG(temp)-32)*0.5556 AS temp, (AVG(max)-32)*0.5556 AS max, (AVG(min)-32)*0.5556 AS min
FROM [fh-bigquery:weather_gsod.gsod2015] gsod
JOIN [fh-bigquery:weather_gsod.stations2] stations
ON gsod.wban=stations.wban AND gsod.stn=stations.usaf
WHERE country='SA'
GROUP BY stn, mo
ORDER BY mo
假设这个查询确实检索到我需要的信息,我该如何重写它以便我可以包含整个范围(1929 到 2016)?
您应该使用 Table wildcard functions,如下所示
SELECT
stn,
FIRST(name) AS station_name,
mo,
(AVG(temp)-32)*0.5556 AS temp,
(AVG(max)-32)*0.5556 AS max,
(AVG(min)-32)*0.5556 AS min
FROM (
SELECT * FROM
(TABLE_QUERY([fh-bigquery:weather_gsod], 'table_id CONTAINS "gsod"'))
) gsod
JOIN [fh-bigquery:weather_gsod.stations2] stations
ON gsod.wban=stations.wban AND gsod.stn=stations.usaf
WHERE country='SA'
GROUP BY stn, mo
ORDER BY mo