Consecutive Spending Growth

Start Timer

0:00:00

Upvote
0
Downvote
Save question
View comments

We’re given a transactions table where each row is a single card transaction with an amount and a timestamp. Write a query to find the user_id of every user whose total monthly spending strictly increased across three consecutive calendar months.

Assume amounts are positive, timestamps and user IDs are non-null, and calendar months use one consistent timezone. A month with no transactions counts as zero spending and breaks a streak, so only months in which the user actually spent money can form the run.

Input:

transactions table

Column Type
id INTEGER
user_id INTEGER
amount FLOAT
created_at DATETIME

Output:

Column Type
user_id INTEGER

Adapted from an interview report · 2026-05-30. Details and assumptions have been adapted for practice; this is not a verbatim interview question.

.
.
.
.
.


Comments

Loading comments