简体   繁体   English

大查询 SQL - 每 n 个数字分组

[英]Big Query SQL - Group into every n numbers

I have a table that includes a column called minutes_since .我有一个表,其中包含一个名为minutes_since的列。 It is an integer containing the number of minutes since a pre-defined event.它是一个 integer,包含自预定义事件以来的分钟数。 Multiple rows maybe fall within the same minute.多行可能落在同一分钟内。

I want to group and aggregate the rows into every n minutes.我想每 n 分钟对行进行分组和聚合。 For example, I want to get the average of another column for all rows occurring within 5 minute intervals.例如,我想获取 5 分钟间隔内出现的所有行的另一列的平均值。

How could this be achieved in big query standard sql?这如何在大查询标准 sql 中实现?

#standardSQL
SELECT 
  MIN(minutes_since) minute_start, 
  MAX(minutes_since) minute_end,  
  AVG(value) value_avg
FROM `project.dataset.table` 
GROUP BY DIV(minutes_since - 1, 5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM