User Engagement Score
What is the total usage time in minutes for each user across all their product sessions?
- Joins
- Aggregation
- NULL handling
- Sorting
Challenge brief
Understand the request
Customer Success is building a product health score for each customer and needs total usage time as the primary engagement signal.
Sum usage_minutes per user_id from usage_logs.
Return
- user_id
- total_usage
Constraints
- Include registered users with no usage and report zero minutes for them
- Order by user ID
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
users
user_idINTEGERcountryTEXT
usage_logs
log_idINTEGERuser_idINTEGERproduct_idINTEGERusage_dateDATEusage_minutesINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
All usage data is in usage_logs. Single-table aggregation: GROUP BY user_id and SUM usage_minutes.
Hint 2
SELECT user_id, SUM(usage_minutes) AS total_usage FROM usage_logs GROUP BY user_id.
Hint 3
Build question 19 from the required result grain: choose the driving table, add only the joins and filters needed for that grain, then apply aggregation and deterministic ordering.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT u.user_id, COALESCE(SUM(ul.usage_minutes), 0) AS total_usage FROM users u LEFT JOIN usage_logs ul ON u.user_id = ul.user_id GROUP BY u.user_id ORDER BY u.user_id;Why this works
Start from registered users, preserve users without usage, and convert only their missing aggregate to zero minutes.
Success check
12 users — user 8 leads (580 min), user 10 lowest (95 min)
Expected result
Use this output to verify values, aliases, ordering, and row count.
| user_id | total_usage |
|---|---|
| 1 | 210 |
| 2 | 60 |
| 3 | 200 |
| 4 | 150 |
| 5 | 180 |
| 6 | 110 |
| 7 | 210 |
| 8 | 580 |
| 9 | 100 |
| 10 | 95 |
Previewing 10 of 13 expected rows. Run the query in the editor to inspect the full result.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Apple
Independent Apple-style product, retail, services, support, workforce, and device-usage SQL practice.
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Amazon
Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice.
Return to the complete interview preparation experience.