Question

Let’s say I have an Angry Birds game.

I want to know how many players are buying the ‘mighty eagle’ weapon each month out of the players which bought the mighty eagle weapon in the previous months in their LTV in the system

I have the dates of all items bought per each client.

What I practically would like to have is a two dimensional matrix that will tell me what the percentage of the players which moved from LTV_month_X to LTV_month_Y for each combination of X<Y for a specific current month?

An example:

example_png (it didn't let me to put the pic inline so please press the link to see the pic)

Now, I have found a way to get the number of players moved actually from from LTV_month_X to LTV_month_Y that LTV_month_Y is their current month of activity within the system using SQL query and Excel Pivot table.

What I try find out is mainly is how to get the base number of those who potentially could do that transition.

A few definitions: LTV_month_X = DATEDIFF(MONTH, first_eagle_month, specific_eagle_month)+1

Preferably I would like to have the solutions in ANSI-SQL, if not then MySQL or MSSQL but no Oracle functions should be used at all.

Since I’m looking for the percentage of the transition two-steps plans could also work, first find the potential ones and the find the actual ones who moved to measure the retention from  LTV_month_X to LTV_month_Y.

One last issue: I need for it to be possible to drill down and find the actual IDs of the clients who moved from any stage X to any other stage Y (>X).

Was it helpful?

Solution

The two dimension you are looking for are

  1. Actual purchase month
  2. Relative purchase month

SELECT 
   player_id, 
   TRUNCATE(first_purchase,'MM') AS first_month , 
   TRUNCATE(current_purchase_date ,'MM') AS purchase_month, 
   months_between(current_purchase _date, first_purchase_date)+1 AS relative_month, 
   SUM(purchase_amount) AS total_purchase, 
   COUNT(DISTINCT player_id) AS player_count 
FROM ...  

Now you can pivot purchase month to relative month and aggregate

OTHER TIPS

The use of the term LTV here is not clear. I assume you mean the lifetime of the user.

If I understand the question, you are asking, based on a list of entities each with one or more events, how do I group (e.g. count) the entities by the month of the last event and the month of the one before last event.

in mysql, you can use a variable to do that. I'm not going to expalin the whole concept, but basically, when within a SELECT statement you write @var:=column, then that variable is assigned the value of that column, and you can use that to compare values between consectuive columns e.g. LEAST(IF(@var=column,@same:=@same+1,@same:=0),@var:=column)

the use of LEAST is a trick to ensure execution order.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top