You can use the RANK() function to rank the purchases based on their purchase date and then select the purchase with the highest rank. You can also use the PARTITION BY clause to rank the purchases separately for each customer.