BigQuery中有一些时间序列数据,看起来像这个
时间戳 | ||
---|---|---|
2018-08-20 04:01:00 | 5 | |
2018-08-20 04:04:00 | 6 | |
2018-08-20 04:05:00 | 5 | |
2018-08-20 04:06:00 | 5 | |
2018-08-20 04:10:00 | 5 | |
2018-08-20 04:22:00 | 6 | |
2018-08-20 04:30 | 6 | |
2018-08-20 04:59:00 | 7 |
您可以(相对(轻松地选择每15分钟间隔中的第一个:
select t.* (except seqnum)
from (select t.*,
row_number() over (partition by floor(timestamp_seconds(timestamp) / (60 * 15)) order by timestamp) as seqnum
from t
) t
where seqnum = 1;
您也可以使用qualify
:来完成此操作
select t.*
from t
qualify row_number() over (partition by floor(timestamp_seconds(timestamp) / (60 * 15)) order by timestamp) = 1;
这个想法是将时间戳转换为秒数。然后将其除以60*15
——15分钟间隔内的秒数。