Repeat Callers Within 7 Days
Zoom 🧠 Hard SQL
Beginner Mode

Objective

Write a SQL query to count the number of unique callers who made multiple calls within a 7-day interval of each other. A caller who made more than two qualifying calls should only be counted once.

Table Schema:

  • caller_history
Column Type Description
caller_id INTEGER Unique identifier for the caller
recipient_id INTEGER Unique identifier for the call recipient
call_date DATE Date the call was made

Task Requirements:

  • A caller qualifies if they have at least two calls where the gap between consecutive calls is 7 days or fewer
  • Two calls on the same day (gap of 0) count as within 7 days
  • Each qualifying caller should be counted exactly once regardless of how many close calls they made
  • Output a single count of unique qualifying callers

Output columns: unique_callers

Examples

Example 1:

Input:

caller_history
call_datecaller_idrecipient_id
2024-01-0112
2024-01-0513
2024-01-0121
2024-01-1023
2024-01-0331
2024-01-0832
2024-01-2031

Output:
unique_callers
2
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 →