sample_input_table
user name action date
1 aaa view 2020-09-03
2 bbb view 2020-09-02
3 ccc view 2020-08-28
4 ddd view 2020-08-25
1 aaa purchase 2020-09-09
I have a table with huge number of rows, the table looks like above.
question
- i want to print the rows which have
purchaseaction and - at the same time, the user who did
purchasemust have row withviewaction - and at the same time, that
viewaction will be in the date range of purchase_date(2020-09-09) and purchase_date - 7days(2020-09-02).
I want to achieve these 3 point in one sql query
sample_output
user name action date
1 aaa purchase 2020-09-09
if we see sample output from the sample input
- our end result have only purchase_events
- purchased_user had a row with
viewaction - and that
viewwas there in the timeframe of2020-09-09and2020-09-02(purchased_date, purchased_date - 7 days)
Can anyone suggest some solution for this?