Loading...

Trend Spotter

A medium SQL interview practice problem on DataDriven. Write and execute real sql code with instant grading.

Domain
SQL
Difficulty
medium

Problem

Data science wants to model spending trends per user over time. For every row in transactions, pull that user's previous transaction amount (by transaction_date) onto the same row, leaving the value empty on a user's first transaction. Return the user_id, total_amount, transaction_date, and the previous amount.

Practice This Problem

Solve this SQL problem with real code execution. DataDriven runs your SQL queries against a live PostgreSQL database and grades it instantly.