Related to How to fill missing dates in BigQuery?, but without back filling/forward filling:
Suppose I have the following sales data:
order_date product store sales
_______________________________________________________
2021-05-01 1 1 10
2021-05-04 1 1 5
2021-04-25 1 2 3
2021-04-30 1 2 9
2021-05-10 1 2 1
2021-05-02 2 1 3
2021-05-04 2 1 3
and my desired output is to fill empty dates w/ 0, but partitioned on product and store (and not to back fill to a global MIN(DATE) or forward fill to a global MAX(DATE):
order_date product store sales
_______________________________________________________
2021-05-01 1 1 10
2021-05-02 1 1 0
2021-05-03 1 1 0
2021-05-04 1 1 5
2021-04-25 1 2 3
2021-04-26 1 2 0
... ... ... ... (all 0s)
2021-04-29 1 2 0
2021-04-30 1 2 9
... ... ... ... (all 0s)
2021-05-10 1 2 1
2021-05-02 2 1 3
2021-05-03 2 1 0
2021-05-04 2 1 3
How would I accomplish this (specifically in BigQuery)?
My initial thought is that I may need to create a table like
SELECT
product, store,
MIN(order_date) min_date,
MAX(order_date) max_date
FROM mydata
GROUP BY product, store
but I'm not sure how I'd use that to partition the original mydata table and fill dates between with IFNULL(sales,0) sales
Thanks in advance!
