You are given two tables: Signups and Confirmations.
The Signups table contains information about user signup times, and the Confirmations table records confirmation message requests with their timestamps and actions.
Write a SQL query to find the IDs of users that requested a confirmation message twice within a 24-hour window. Two messages exactly 24 hours apart are considered to be within the window.
Important notes:
- The action ('confirmed' or 'timeout') does not affect the answer
- Only the request time matters for determining the 24-hour window
- Return the result in any order
Table Schema
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | Unique user identifier |
time_stamp
|
datetime | User signup timestamp |
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | User identifier (foreign key to Signups) |
time_stamp
PK
|
datetime | Confirmation request timestamp |
action
|
ENUM('confirmed', 'timeout') | Result of confirmation request |
Input & Output
| user_id | time_stamp |
|---|---|
| 3 | 2020-03-21 10:16:13 |
| 7 | 2020-01-04 13:57:59 |
| user_id | time_stamp | action |
|---|---|---|
| 3 | 2020-03-21 10:16:13 | confirmed |
| 3 | 2020-03-22 08:30:00 | timeout |
| 7 | 2020-01-05 03:30:17 | confirmed |
| user_id |
|---|
| 3 |
User 3 requested confirmation messages at 2020-03-21 10:16:13 and 2020-03-22 08:30:00. The time difference is approximately 22 hours and 14 minutes, which is within the 24-hour window. User 7 only has one confirmation request, so they don't qualify.
| user_id | time_stamp |
|---|---|
| 1 | 2020-01-01 12:00:00 |
| 2 | 2020-01-02 12:00:00 |
| user_id | time_stamp | action |
|---|---|---|
| 1 | 2020-01-01 15:00:00 | confirmed |
| 2 | 2020-01-05 10:00:00 | timeout |
| user_id |
|---|
Each user only has one confirmation request, so no user qualifies as having requested confirmation messages twice within a 24-hour window. The result is empty.
| user_id | time_stamp |
|---|---|
| 5 | 2020-02-01 10:00:00 |
| user_id | time_stamp | action |
|---|---|---|
| 5 | 2020-02-01 12:00:00 | timeout |
| 5 | 2020-02-02 12:00:00 | confirmed |
| user_id |
|---|
| 5 |
User 5 has confirmation requests exactly 24 hours apart (2020-02-01 12:00:00 and 2020-02-02 12:00:00). Since requests exactly 24 hours apart are considered within the window, user 5 qualifies.
Constraints
-
1 ≤ user_id ≤ 1000 -
actionis either'confirmed'or'timeout' - Each user can have multiple confirmation requests
- Two messages exactly 24 hours apart are within the window