Sql Bigquery-达到总和时查找
我试图通过BigQuery上的NOAA全球地表当日天气数据汇总,找出2012年总降水量超过2英寸的日期,以及以下stn和wban值722616和03032 这是我到目前为止构建的查询:Sql Bigquery-达到总和时查找,sql,google-bigquery,Sql,Google Bigquery,我试图通过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
#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的日期值
谢谢你的帮助
谢谢 您可以使用累计总和:
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;
您可以使用累积总和:
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;
这可以在过滤prcp>=2时完成
如果您对累计总和超过2.0的日期感兴趣,请使用中提到的窗口函数,这可以在过滤prcp>=2时完成
如果您对累计总和超过2.0的日期感兴趣,请使用谢谢!你有没有可能解释一下这个问题的来龙去脉?更具体地说,根据mo,da运行的按年份划分的sumprcp顺序:根据mo,da是一个标准窗口函数,它以累积方式对降水量求和。每一行只对前几行求和,而不是对整个集合求和。这样,你就可以知道什么时候超过2.0谢谢!你有没有可能解释一下这个问题的来龙去脉?更具体地说,根据mo,da运行的按年份划分的sumprcp顺序:根据mo,da是一个标准窗口函数,它以累积方式对降水量求和。每一行只对前几行求和,而不是对整个集合求和。这样,你就可以知道当它超过2.0时,a.prcp是一年的累积降水量,还是仅仅是某一行的降水量?它是该行某一天的降水量是a.prcp是该年的累积降水量,还是仅仅是某一行某一天的降水量?它是该行某一天的降水量