【问题标题】:Big Query multiple tablesBig Query 多表
【发布时间】:2014-05-04 17:55:29
【问题描述】:

我正在尝试从 Google 的 BigQuery 中的多个表中进行查询。我收到错误“在表'weather.stations'中找不到字段'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]。有任何想法吗?谢谢!

【问题讨论】:

  • 错误明确表示不存在这样的字段。
  • 要回答这个问题,强烈需要了解这些表的结构。您能否显示字段列表或在可能看到的地方提供参考?

标签: sql google-bigquery


【解决方案1】:

听起来您正在尝试进行 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;

【讨论】:

    猜你喜欢
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 1970-01-01
    • 2017-09-10
    • 2020-09-04
    相关资源
    最近更新 更多