I’ll say right away that I’m familiar with BigQuery superficially, but there is a task that needs to be solved by means of this system without resorting to using other tools. The bottom line is that BigQuery does not allow the use of cycles, and I cannot imagine how to solve this problem without them. Maybe someone has thoughts on this, and you can tell in which direction to dig?
The task itself sounds like this. There is a table with data, where for each date there is a set of user IDs - every day new users appear (for the first time), old ones disappear, and some remain (previously). It is necessary to calculate for each date, the number of users from the current date is in the next N, while they are not in the previous one. For example, the number of users from a cell for January 2, is for January 3-6, but they were not on January 1st.
The number of dates is finite, but the range is floating (maybe 5 dates, maybe 50, etc.) - that’s why the thoughts about the cycle arise, and I don’t imagine how to solve without it.
In other words, for clarity,
Given:
date id 01.01.2019 1 01.01.2019 2 01.01.2019 3 01.01.2019 4 01.01.2019 5 02.01.2019 2 02.01.2019 3 02.01.2019 4 03.01.2019 1 03.01.2019 2 03.01.2019 5 03.01.2019 6 04.01.2019 1 04.01.2019 2 04.01.2019 7 At the output you need to get the following table:
---- 1день 2день 3день 4день 1янв 5 3 3 2 2янв 3 1 1 - 3янв 4 2 - - 4янв 3 - - - I am grateful for any help, I have already reread a lot of things, but I really couldn’t apply it.