Calculate User Revenue and Session Duration in Python
Company: Upstart
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency in data manipulation and time-series event processing in Python, focusing on per-user revenue aggregation and sessionization to compute average session duration.
Tables
events(user_id INTEGER, event_type VARCHAR(20), revenue DECIMAL(10,2), timestamp TIMESTAMP)
Hints
- Group rows by user_id to aggregate all events per user.
- Compute session duration as the difference between MAX(timestamp) and MIN(timestamp) per user, then convert that interval to seconds.