|
| 1 | +--- |
| 2 | +comments: true |
| 3 | +difficulty: Easy |
| 4 | +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3172.Second%20Day%20Verification/README_EN.md |
| 5 | +--- |
| 6 | + |
| 7 | +<!-- problem:start --> |
| 8 | + |
| 9 | +# [3172. Second Day Verification 🔒](https://leetcode.com/problems/second-day-verification) |
| 10 | + |
| 11 | +[中文文档](/solution/3100-3199/3172.Second%20Day%20Verification/README.md) |
| 12 | + |
| 13 | +## Description |
| 14 | + |
| 15 | +<!-- description:start --> |
| 16 | + |
| 17 | +<p>Table: <code>emails</code></p> |
| 18 | + |
| 19 | +<pre> |
| 20 | ++-------------+----------+ |
| 21 | +| Column Name | Type | |
| 22 | ++-------------+----------+ |
| 23 | +| email_id | int | |
| 24 | +| user_id | int | |
| 25 | +| signup_date | datetime | |
| 26 | ++-------------+----------+ |
| 27 | +(email_id, user_id) is the primary key (combination of columns with unique values) for this table. |
| 28 | +Each row of this table contains the email ID, user ID, and signup date. |
| 29 | +</pre> |
| 30 | + |
| 31 | +<p>Table: <code>texts</code></p> |
| 32 | + |
| 33 | +<pre> |
| 34 | ++---------------+----------+ |
| 35 | +| Column Name | Type | |
| 36 | ++---------------+----------+ |
| 37 | +| text_id | int | |
| 38 | +| email_id | int | |
| 39 | +| signup_action | enum | |
| 40 | +| action_date | datetime | |
| 41 | ++---------------+----------+ |
| 42 | +(text_id, email_id) is the primary key (combination of columns with unique values) for this table. |
| 43 | +signup_action is an enum type of ('Verified', 'Not Verified'). |
| 44 | +Each row of this table contains the text ID, email ID, signup action, and action date. |
| 45 | +</pre> |
| 46 | + |
| 47 | +<p>Write a Solution to find the user IDs of those who <strong>verified</strong> their <strong>sign-up</strong> on the <strong>second day</strong>.</p> |
| 48 | + |
| 49 | +<p>Return <em>the result table ordered by</em> <code>user_id</code> <em>in <strong>ascending</strong> order</em>.</p> |
| 50 | + |
| 51 | +<p>The result format is in the following example.</p> |
| 52 | + |
| 53 | +<p> </p> |
| 54 | +<p><strong class="example">Example:</strong></p> |
| 55 | + |
| 56 | +<div class="example-block"> |
| 57 | +<p><strong>Input:</strong></p> |
| 58 | + |
| 59 | +<p>emails table:</p> |
| 60 | + |
| 61 | +<pre class="example-io"> |
| 62 | ++----------+---------+---------------------+ |
| 63 | +| email_id | user_id | signup_date | |
| 64 | ++----------+---------+---------------------+ |
| 65 | +| 125 | 7771 | 2022-06-14 09:30:00| |
| 66 | +| 433 | 1052 | 2022-07-09 08:15:00| |
| 67 | +| 234 | 7005 | 2022-08-20 10:00:00| |
| 68 | ++----------+---------+---------------------+ |
| 69 | +</pre> |
| 70 | + |
| 71 | +<p>texts table:</p> |
| 72 | + |
| 73 | +<pre class="example-io"> |
| 74 | ++---------+----------+--------------+---------------------+ |
| 75 | +| text_id | email_id | signup_action| action_date | |
| 76 | ++---------+----------+--------------+---------------------+ |
| 77 | +| 1 | 125 | Verified | 2022-06-15 08:30:00| |
| 78 | +| 2 | 433 | Not Verified | 2022-07-10 10:45:00| |
| 79 | +| 4 | 234 | Verified | 2022-08-21 09:30:00| |
| 80 | ++---------+----------+--------------+---------------------+ |
| 81 | + </pre> |
| 82 | + |
| 83 | +<p><strong>Output:</strong></p> |
| 84 | + |
| 85 | +<pre class="example-io"> |
| 86 | ++---------+ |
| 87 | +| user_id | |
| 88 | ++---------+ |
| 89 | +| 7005 | |
| 90 | +| 7771 | |
| 91 | ++---------+ |
| 92 | +</pre> |
| 93 | + |
| 94 | +<p><strong>Explanation:</strong></p> |
| 95 | + |
| 96 | +<ul> |
| 97 | + <li>User with email_id 7005 signed up on 2022-08-20 10:00:00 and verified on second day of the signup.</li> |
| 98 | + <li>User with email_id 7771 signed up on 2022-06-14 09:30:00 and verified on second day of the signup.</li> |
| 99 | +</ul> |
| 100 | +</div> |
| 101 | + |
| 102 | +<!-- description:end --> |
| 103 | + |
| 104 | +## Solutions |
| 105 | + |
| 106 | +<!-- solution:start --> |
| 107 | + |
| 108 | +### Solution 1: Joining Two Tables |
| 109 | + |
| 110 | +We can join the two tables and then use the `DATEDIFF` function to calculate whether the difference between the registration date and the operation date is equal to 1, and whether the registration operation is `Verified`, to filter out the user IDs that meet the conditions. |
| 111 | + |
| 112 | +<!-- tabs:start --> |
| 113 | + |
| 114 | +#### MySQL |
| 115 | + |
| 116 | +```sql |
| 117 | +# Write your MySQL query statement below |
| 118 | +SELECT user_id |
| 119 | +FROM |
| 120 | + Emails AS e |
| 121 | + JOIN texts AS t |
| 122 | + ON e.email_id = t.email_id |
| 123 | + AND DATEDIFF(action_date, signup_date) = 1 |
| 124 | + AND signup_action = 'Verified' |
| 125 | +ORDER BY 1; |
| 126 | +``` |
| 127 | + |
| 128 | +<!-- tabs:end --> |
| 129 | + |
| 130 | +<!-- solution:end --> |
| 131 | + |
| 132 | +<!-- problem:end --> |
0 commit comments