← Amazon Interview Insights

Amazon·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Amazon DS interview, got a SQL question about computing monthly cohort retention for a tenant activity dataset. Pretty involved problem with a lot of moving parts, more of a take-home style prompt than a quick whiteboard thing.

Questions Asked (1)

Q1

Given a users table and an activity table, write a SQL query to compute a monthly cohort retention table. Each tenant's cohort is defined by the calendar month of their earliest activity timestamp (not signup date). For each cohort, calculate how many tenants were active in each subsequent month, and output the cohort month, cohort size, month number, retained user count, and retention rate rounded to 4 decimal places.

Data ModelingProduct Analytics & MetricsAlgorithms & Data Structures
Author's notes

The tricky part is that cohort assignment uses the earliest activity_ts, not signup_date.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions, then outline a multi-step SQL approach using CTEs: first find each tenant's earliest activity month (cohort month), then join back to the activity table to get all subsequent activity months, and finally aggregate to compute cohort size, retained counts, and retention rates. Emphasize handling edge cases like tenants with no activity after cohort month and ensuring correct month numbering.

Pro tip: Mention that retention is typically calculated based on distinct active tenants per month, and that using date truncation to month and a self-join or window function can efficiently compute month numbers. Also, note that rounding should be applied at the final step to avoid precision issues.

1. Clarify requirements and schema

Confirm the table structures, definitions of 'active', and that cohort is based on earliest activity timestamp, not signup. Ask about handling tenants with no subsequent activity.

2. Identify cohort month per tenant

Use a subquery or CTE to find the minimum activity timestamp per tenant, then truncate to month to get the cohort month.

3. Compute month number and retention

Join the cohort month back to the activity table, calculate the month difference between activity month and cohort month as month_number, and count distinct active tenants per cohort and month_number.

4. Calculate retention rate and format output

Compute retention rate as retained count divided by cohort size, round to 4 decimal places, and ensure the output includes cohort month, cohort size, month number, retained count, and retention rate.

Key Points to Mention

  • Use of CTEs for readability and stepwise logic
  • Date truncation to month (e.g., DATE_TRUNC('month', timestamp))
  • Month number calculation using DATEDIFF or equivalent
  • Counting distinct tenants to avoid duplicates
  • Handling of month 0 (cohort month) retention, which is always 100%
  • Rounding retention rate to 4 decimal places using ROUND()

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.