I have a table like:
month | type | email
-----+------+------
2015-08-01 | questionnaire | email1@gmail.com
-----+------+------
2016-08-01 | creation | email1@gmail.com
-----+------+------
2018-12-01 | buy | email1@gmail.com
-----+------+------
2020-02-01 | questionnaire | email2@gmail.com
-----+------+------
2021-08-01 | creation | email2@gmail.com
-----+------+------
2021-11-01 | buy | email2@gmail.com
I want to generate a table that has, for all emails, every month since min(month) until current_date(). As for the type column, the value should be the "strongest" with questionnaire < creation < buy.
For example:
- if on 2018-08-01, I have a type buy, then all months until current_date() should have this type.
- if on 2017_12-01, I have a type qustionnaire, and then, on 2020-01-01 I have a creation type, then all month from 2017_12-01 until 2020-01-01 should be questionnaire type. Then, from 2020-01-01 until current_date, it should be creation type.
Any idea how to do it in bigquery?
One additional comment: It's very important to respect the priority questionnaire < creation < buy. If the first event type that happens is the strongest ("buy"), then all following months will necessary be a "buy" type. A type cannot go to a lower type later on.
