timestamp | id | scope |
---|---|---|
2021-01-23 12:52:34.159999 UTC | 1 | enter_page |
2021-01-23 12:53:02.342 UTC | 1 | view_product |
2021-01-23 12:53:02.675 UTC | 1 | checkout |
2021-01-23 12:53:04.342 UTC | 1 | search_page |
2021-01-23 12:53:24.513 UTC | 1 | checkout |
I am trying to get all the values between the FIRST_VALUE and LAST VALUE in the column 'scope' using WINDOWS/ANALYTICAL Functions
I already get the first_value() = enter_page
and the last_value() == checkout
by using windows functions in SQLite
FIRST_VALUE(scope) OVER ( PARTITION BY id ORDER BY julianday(timestamp) ASC) first_page
FIRST_VALUE(scope) OVER ( PARTITION BY id ORDER BY julianday(timestamp) DESC ) last_page
I am trying to capture all steps in between [excluding edges]: view_product, apartment_view, checkout[, N-field] to later add them into a string ( unique values -STR_AGGR() )
Once done that, i will later process trying to find if the customer at somepoint during the purchase_journey open the checkout multiple times
my result should like like
id | first_page | last_page | inbetween_pages |
---|---|---|---|
1 | enter_page | checkout | view_product, checkout, search_page |
p.s. I am trying to avoid using python to process this. I would like a 'clean' way of doing this with SQL-pure
Thanks a lot guys
Hmmm . . . I am thinking:
In SQLite,
group_concat()
doesn't accept anorder by
argument. My understanding is that it respects the ordering from the subquery, which is why the subquery has anorder by
.