Skip to content
Advertisement

Calculating average time (in days) between customer first and second order on BigQuery

I’m trying to figure out the avg days it takes for a customer to repeat purchase.

Here is what I have

It’s returning this

I want to now get the average days between all first and second purchases, then second and third et

Sample data set

|---------------------|------------------|------------------|------------------| | Email_address | Order_name | Order_number | Date | |---------------------|------------------|------------------|------------------| | test@test.com | 364 | 1 | 2019-08-11 | |---------------------|------------------|------------------|------------------| | test@test.com | 366 | 2 | 2019-08-29 | |---------------------|------------------|------------------|------------------| | j@test.com | 495 | 1 | 2019-09-04 | |---------------------|------------------|------------------|------------------| | j@test.com | 564 | 2 | 2019-10-04 | |---------------------|------------------|------------------|------------------|

I want to find the avg time difference between the orders of both customers. test@test.com = 18 days j@test.com = 30 days

Average = 24 days

Advertisement

Answer

You seem to be asking for an aggregation query:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement