我正在尝试使用BigQuery上的NOAA全球地面天气摘要,找出2012年的总降水量在什么日期和2英寸以下的以下stn和wban值722616和03032。
这是我到目前为止构建的查询:
#standardSQL
select a.prcp, concat(year, mo, da) as date, a.stn, a.wban
from `bigquery-public-data.noaa_gsod.gsod*` a
where _TABLE_SUFFIX = '2012' and a.stn = '722616' and a.wban = '03032'
order by date;
但是,我不确定如何实际输出prcp> 2的日期值。
感谢您的帮助
谢谢!
答案 0 :(得分:3)
您可以使用累计金额:
select *
from (select prcp, concat(year, mo, da) as date, stn, wban,
sum(prcp) over (partition by year order by mo, da) as running_prcp
from `bigquery-public-data.noaa_gsod.gsod*` g
where _TABLE_SUFFIX = '2012' and stn = '722616' and wban = '03032'
) x
where running_prcp >= 2.0 and running_prcp - prcp < 2.0
order by date;
答案 1 :(得分:0)
这可以在您过滤prcp >= 2
#standardSQL
select Min(date),stn, wban, array_agg(prcp) from
(select a.prcp, concat(year, mo, da) as date, a.stn, a.wban
from `bigquery-public-data.noaa_gsod.gsod*` a
where _TABLE_SUFFIX = '2012' and a.stn = '722616' and a.wban = '03032'
order by date) f
where prcp >=
group by stn,wban
如果您对累计金额超过2.0的日期感兴趣,请使用Gordon
中提到的窗口函数