Skip to content

Commit 289c42c

Browse files
committed
task: #1934
1 parent 985dc43 commit 289c42c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Have a good contributing!
8181
- [1193. Monthly Transactions I](./leetcode/medium/1193.%20Monthly%20Transactions%20I.sql)
8282
- [1341. Movie Rating](./leetcode/medium/1341.%20Movie%20Rating.sql)
8383
- [1907. Count Salary Categories](./leetcode/medium/1907.%20Count%20Salary%20Categories.sql)
84+
- [1934. Confirmation Rate](./leetcode/medium/1934.%20Confirmation%20Rate.sql)
8485
3. [Hard](./leetcode/hard/)
8586
- [185. Department Top Three Salaries](./leetcode/hard/185.%20Department%20Top%20Three%20Salaries.sql)
8687

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Question 1934. Confirmation Rate
3+
Link: https://leetcode.com/problems/confirmation-rate/description/?envType=study-plan-v2&envId=top-sql-50
4+
5+
Table: Signups
6+
7+
+----------------+----------+
8+
| Column Name | Type |
9+
+----------------+----------+
10+
| user_id | int |
11+
| time_stamp | datetime |
12+
+----------------+----------+
13+
user_id is the column of unique values for this table.
14+
Each row contains information about the signup time for the user with ID user_id.
15+
16+
17+
Table: Confirmations
18+
19+
+----------------+----------+
20+
| Column Name | Type |
21+
+----------------+----------+
22+
| user_id | int |
23+
| time_stamp | datetime |
24+
| action | ENUM |
25+
+----------------+----------+
26+
(user_id, time_stamp) is the primary key (combination of columns with unique values) for this table.
27+
user_id is a foreign key (reference column) to the Signups table.
28+
action is an ENUM (category) of the type ('confirmed', 'timeout')
29+
Each row of this table indicates that the user with ID user_id requested a confirmation message at time_stamp and that confirmation message was either confirmed ('confirmed') or expired without confirming ('timeout').
30+
31+
32+
The confirmation rate of a user is the number of 'confirmed' messages divided by the total number of requested confirmation messages. The confirmation rate of a user that did not request any confirmation messages is 0. Round the confirmation rate to two decimal places.
33+
34+
Write a solution to find the confirmation rate of each user.
35+
36+
Return the result table in any order.
37+
*/
38+
39+
SELECT
40+
s.user_id,
41+
COALESCE(CASE
42+
WHEN c.user_id IS NULL THEN 0.00
43+
ELSE ROUND((
44+
SELECT COUNT(c2.user_id)
45+
FROM Confirmations AS c2
46+
WHERE c2.action = 'confirmed' AND c2.user_id = s.user_id
47+
GROUP BY c2.user_id
48+
) / COUNT(c.user_id)::numeric, 2)
49+
END, 0.00) AS confirmation_rate
50+
FROM Signups AS s
51+
LEFT JOIN
52+
Confirmations AS c
53+
ON s.user_id = c.user_id
54+
GROUP BY s.user_id, c.user_id

0 commit comments

Comments
 (0)