0
Follow
0
View

BigQuery - Aggregate by 2 months window

chengcyx 注册会员
2023-01-25 04:40

Consider below approach

SELECT FORMAT_DATE('%b %Y', 
    DATE(EXTRACT(YEAR FROM CAST(date AS DATE)), 2 * DIV(EXTRACT(MONTH FROM CAST(date AS DATE)) - 1, 2) + 1, 1)
  ) AS Date,
  Market,
  SUM(Rev) AS Rev,
FROM `data_table` 
GROUP BY 1, 2             

with output like below

About the Author

Question Info

Publish Time
2023-01-25 04:40
Update Time
2023-01-25 04:40