Hi everyone,
I have a small problem for which I have found a partly solution.
I have a transactional history of purchases and I'd like to find the average time between purchases for each customer.
For example, my table1 looks like this:
id customerid order_date
1 1111111 03/02/2011
2 2222222 06/03/2011
3 1111111 11/08/2012
4 2222222 10/09/2012
5 3333333 01/02/2013
6 3333333 02/03/2013
7 3333333 22/04/2014
8 1111111 15/07/2014
9 3333333 02/08/2015
10 1111111 11/11/2015
What I am trying to to get is this one:
customerid avg_time_between_orders_in_months
1111111 5.50
2222222 7.85
3333333 6.22
What I've done so far is to find the average time between 1st and 2nd order by creating two temporary tables (one with the initial order for each customer and another one with the 2nd order). However, considering that my transactional history table is huge (more than a million rows) and a customer may have 1 order or 100 orders, I cannot continue this process of creating temporary tables forever.
Has anyone experienced something like this? Ideally, I am trying to find the average values per year, but, if someone can direct me to the solution, I think that I can work on this to estimate on the yearly values.
Any thoughts? :banghead:
Thanks!
I have a small problem for which I have found a partly solution.
I have a transactional history of purchases and I'd like to find the average time between purchases for each customer.
For example, my table1 looks like this:
id customerid order_date
1 1111111 03/02/2011
2 2222222 06/03/2011
3 1111111 11/08/2012
4 2222222 10/09/2012
5 3333333 01/02/2013
6 3333333 02/03/2013
7 3333333 22/04/2014
8 1111111 15/07/2014
9 3333333 02/08/2015
10 1111111 11/11/2015
What I am trying to to get is this one:
customerid avg_time_between_orders_in_months
1111111 5.50
2222222 7.85
3333333 6.22
What I've done so far is to find the average time between 1st and 2nd order by creating two temporary tables (one with the initial order for each customer and another one with the 2nd order). However, considering that my transactional history table is huge (more than a million rows) and a customer may have 1 order or 100 orders, I cannot continue this process of creating temporary tables forever.
Has anyone experienced something like this? Ideally, I am trying to find the average values per year, but, if someone can direct me to the solution, I think that I can work on this to estimate on the yearly values.
Any thoughts? :banghead:
Thanks!