Interview Query

Third Purchase

17
Have you seen this question before?

Given the transactions table below, write a query that finds the third purchase of every user.

Note: Sort the results by the user_id in ascending order. If a user purchases two products at the same time, the lower id field is used to determine which is the first purchase.

Example:

Input:

transactions table

Columns Type
id INTEGER
user_id INTEGER
created_at DATETIME
product_id INTEGER
quantity INTEGER

Output:

Columns Type
user_id INTEGER
created_at DATETIME
product_id INTEGER
quantity INTEGER
Next question: AB Test Ties
.....
MySQL 8.0.17
Loading editor
Use Shift + Enter to run query