Repeat Callers Within 7 Days
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:
Output:
Input:
| caller_history | ||
|---|---|---|
| call_date | caller_id | recipient_id |
| 2024-01-01 | 1 | 2 |
| 2024-01-05 | 1 | 3 |
| 2024-01-01 | 2 | 1 |
| 2024-01-10 | 2 | 3 |
| 2024-01-03 | 3 | 1 |
| 2024-01-08 | 3 | 2 |
| 2024-01-20 | 3 | 1 |
| unique_callers |
|---|
| 2 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Zoom