KatInterview

SQL Analysis and Statistical Testing of App Usage Patterns

SQL & DataModel answer
MediumModel answerSQL & Datasqlaggregationwindow-functions

Last updated

Write SQL queries to identify top apps and compute category distributions, then design a statistical test to compare engagement frequency across user segments.

You have a table tracking application usage on a VR platform:

AppUsage
+---------+--------+-----------+--------------+------------+
| user_id | app_id | category  | minutes_spent| usage_date |
+---------+--------+-----------+--------------+------------+
| 101     | 12     | Social    | 45           | 2023-04-15 |
| 102     | 17     | Game      | 30           | 2023-04-16 |
| 101     | 17     | Game      | 20           | 2023-04-17 |
| 103     | 22     | Fitness   | 25           | 2023-04-17 |
| 104     | 12     | Social    | 60           | 2023-04-18 |
+---------+--------+-----------+--------------+------------+

Your task has three parts:

  1. Write a SQL query to identify which application accumulated the most total usage time during the most recent 30-day period.

  2. Write a SQL query to calculate what proportion of overall usage time each category represents over the same 30-day window.

  3. Describe an approach to test whether users who engage with Social apps demonstrate more consistent usage patterns compared to users who engage with Game apps. Specify the metric you would use, the statistical method, and any important considerations.

For date filtering, assume "the past 30 days" means the 30 complete calendar days before today, excluding today's incomplete data.

Hints

Hint 1

Consider how to handle tied results when identifying the top application

Hint 2

Use window functions to calculate totals across the entire result set without self-joins

Hint 3

Think about what 'consistency' means operationally—is it about frequency of visits or duration per visit?