Skip to content

Commit 4eae197

Browse files
committed
task: #550
1 parent 4a7907f commit 4eae197

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Have a good contributing!
8080
2. [Medium](./leetcode/medium/)
8181
- [176. Second Highest Salary](./leetcode/medium/176.%20Second%20Highest%20Salary.sql)
8282
- [184. Department Highest Salary](./leetcode/medium/184.%20Department%20Highest%20Salary.sql)
83+
- [550. Game Play Analysis IV](./leetcode/medium/550.%20Game%20Play%20Analysis%20IV.sql)
8384
- [570. Managers with at Least 5 Direct Reports](./leetcode/medium/570.%20Managers%20with%20at%20Least%205%20Direct%20Reports.sql)
8485
- [602. Friend Requests II: Who Has the Most Friends](./leetcode/medium/602.%20Friend%20Requests%20II:%20Who%20Has%20the%20Most%20Friends.sql)
8586
- [626. Exchange Seats](./leetcode/medium/626.%20Exchange%20Seats.sql)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Question 550. Game Play Analysis IV
3+
Link: https://leetcode.com/problems/game-play-analysis-iv/description/?envType=study-plan-v2&envId=top-sql-50
4+
5+
Table: Activity
6+
7+
+--------------+---------+
8+
| Column Name | Type |
9+
+--------------+---------+
10+
| player_id | int |
11+
| device_id | int |
12+
| event_date | date |
13+
| games_played | int |
14+
+--------------+---------+
15+
(player_id, event_date) is the primary key (combination of columns with unique values) of this table.
16+
This table shows the activity of players of some games.
17+
Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.
18+
19+
Write a solution to report the fraction of players that logged in again on the day after the day they first logged in, rounded to 2 decimal places. In other words, you need to determine the number of players who logged in on the day immediately following their initial login, and divide it by the number of total players.
20+
*/
21+
22+
WITH logged_again AS (
23+
SELECT
24+
player_id,
25+
MIN(event_date) + INTERVAL '1 day' AS next_event_date
26+
FROM Activity
27+
GROUP BY player_id
28+
)
29+
30+
SELECT
31+
ROUND(COUNT(CASE
32+
WHEN la.next_event_date IS NOT NULL
33+
THEN 1
34+
END) / COUNT(DISTINCT a.player_id)::NUMERIC, 2) AS fraction
35+
FROM Activity AS a
36+
LEFT JOIN
37+
logged_again AS la
38+
ON
39+
a.event_date = la.next_event_date
40+
AND a.player_id = la.player_id
41+

0 commit comments

Comments
 (0)