Big Query多个表

时间:2014-05-04 17:55:30

标签: sql google-bigquery

我试图从Google的BigQuery中的多个表中进行查询。我收到了错误" Field' w.max_temperature'表格' weather.stations'中没有找到。"

这是我的SQL:

SELECT w.station_number, s.LAT, s.LON, w.year, w.month, avg(w.mean_temp) as [mean temp], max(w.max_temperature) as [max temp], min(w.min_temperature) as [min temp], avg(w.mean_visibility) as [avg visbility] FROM [weather.stations] s, [publicdata:samples.gsod] w WHERE w.station_number=s.USAF AND w.wban_number=s.WBAN GROUP BY w.month, w.year, w.station_number, s.LAT, s.LON;

我试图引用" max_temperature"至[publicdata:samples.gsod],但无论出于何种原因,它都将其引用到[weather.stations]。有任何想法吗?谢谢!

1 个答案:

答案 0 :(得分:4)

听起来你正在尝试进行JOIN,但在BigQuery SQL中,以逗号分隔的表列表表示UNION ALL而不是JOIN(是的,它很奇怪;是的,如果我们可能会改变它可能,但现在可能为时已晚。)

您最想要的是:

SELECT w.station_number, s.LAT, s.LON, w.year, w.month, 
       avg(w.mean_temp) as [mean temp], max(w.max_temperature) as [max temp], 
       min(w.min_temperature) as [min temp], 
       avg(w.mean_visibility) as [avg visbility]
FROM [weather.stations] s, 
JOIN [publicdata:samples.gsod] w
ON w.station_number=s.USAF AND w.wban_number=s.WBAN 
GROUP BY w.month, w.year, w.station_number, s.LAT, s.LON;