Messaging Activity Analysis
Meta ☯️ Medium SQL
Beginner Mode

Objective

Write a SQL query to calculate the percentage of time users spend sending messages versus opening messages, grouped by age bucket.

Table Schema:

  • activities
Column Type Description
activity_id INTEGER Unique identifier for each activity
user_id INTEGER ID of the user performing the activity
activity_type VARCHAR Type of activity ('send', 'open')
time_spent DECIMAL Time spent on the activity in minutes
activity_date DATE Date when the activity occurred
  • age_breakdown
Column Type Description
user_id INTEGER ID of the user
age_bucket VARCHAR Age group of the user (e.g., '18-25', '26-35', '36-45')

Task Requirements:

  • Join the activities and age_breakdown tables
  • Calculate total time spent on 'send' and 'open' activities per age group
  • Calculate the percentage of time spent on each activity type
  • Round percentages to 2 decimal places
  • Display age_bucket, send_perc, and open_perc

Output columns: age_bucket, send_perc, open_perc

Examples

Example 1:

Input:

activities
activity_dateactivity_idactivity_typetime_spentuser_id
2024-01-151send10.5101
2024-01-162open5.2101
2024-01-173send8.3102
2024-01-184open12.7102
age_breakdown
age_bucketuser_id
18-25101
18-25102

Output:
age_bucketopen_percsend_perc
18-2548.7751.23
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →