2014-05-04 101 views
4

我試圖從Google的BigQuery中的多個表格進行查詢。我收到表「weather.stations」中找不到的「Field'w.max_temperature'」錯誤。「查詢多個表格

這裏是我的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。有任何想法嗎?謝謝!

+2

這個錯誤清楚地說,沒有這樣的字段存在。 –

+2

要回答這個問題,強烈需要知道這些表格的結構。你可以顯示字段列表或給出一個可以看到它的參考嗎? –

+0

[在Big Query中查詢多個表]可能的重複(http://stackoverflow.com/questions/13171776/querying-multiple-tables-in-big-query) –

回答

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;