KatInterview

Survey Response Rates and Rating Comparison by User Tenure

SQL & DataModel answer
MediumModel answerSQL & Datasqlaggregationcohort-analysis

Last updated

Compute an overall survey response rate and compare average notification ratings across user tenure cohorts using SQL joins, aggregation, and bucketing.

Notification Survey Analysis

A mobile app prompts users to rate push notifications through in-app surveys. Two tables capture the relevant data:

survey_responses

user_idevent_datetrigger_typescore
1012023-01-10notif_popup5
1022023-01-11notif_popup3
1012023-01-12notif_modal4

score is an integer from 1–5, or NULL if the user dismissed the survey without answering.

user_accounts

user_idsignup_datecountry
1012022-12-20US
1022023-01-05CA
1032023-01-07US

Tasks

Part 1. Write a SQL query to compute the overall survey response rate — both at the impression level (what share of surveys shown received a response) and at the user level (what share of users who were shown a survey responded at least once).

Part 2. Write a SQL query to determine whether recently-registered users tend to rate notifications differently than long-tenured users. Group users into tenure buckets based on how many days had elapsed since signup at the time of the survey, then compute per-bucket response rate, average score, median score, and the number of distinct users.

Use PostgreSQL syntax. Briefly explain your assumptions, call out any edge cases, and state the time and space complexity of each query.

Hints

Hint 1

Before writing any SQL, decide what 'response rate' means: impressions with a non-NULL score divided by total impressions, not something you can read off a table that only logs answers. If the table logged only answered surveys, you would need a separate impressions table — say that out loud.

Hint 2

Measure tenure at survey time (event_date minus signup_date), not as of today. A user registered a year ago who answered in their first week was a new user when they rated. Use this per-row calculation as the basis for your bucket CASE expression.

Hint 3

After bucketing, compute both the event-level average (all rows) and the user-level average (one mean per user, then average those). They can diverge when a few users submit many responses in one bucket, and surfacing both shows the interviewer you understand Simpson's paradox-style distortions.