Return the customer's last purchase

  1. Navigate to the Query Editor.

2. Grab the customer's last purchase:

The first part of the query is to return the customer’s last purchase. We can do this by querying the CustomerPurchaseActivities collection and ordering the _event_time in descending order. We’ll need to return the results for an _id. To do this, we’ll create a parameter, so we can put any _id we want.

Major SQL code highlights:

  • On line 8, you’ll notice there is a :userid. This is the parameter we’ll create.

3. Create the parameter:

Navigate to the parameters tab and add the parameter with these details:

4. Create the parameter with these details:

  • Parameter name: userid

  • Type: string

  • Value: 2

4. Run the query! If you don’t see results, it’s because the customer hasn’t made a purchase. Change the :userid to a new string to see if the results are not null.

NOTE: You can find us on the Rockset Community if you have questions or comments about the workshop.

Last updated