550. Game Play Analysis IV
https://leetcode.com/problems/game-play-analysis-iv/
Game Play Analysis IV - LeetCode
Can you solve this real interview question? Game Play Analysis IV - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Write an SQL query 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 count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.
처음 로그인한 날 다음 날 다시 로그인한 플레이어의 비율을 소수점 둘째 자리에서 반올림하여 보고합니다. 즉, 첫 로그인 날짜부터 연속 2일 이상 로그인한 플레이어 수를 세고 그 수를 총 플레이어 수로 나누어야 합니다.
# 1
SELECT ROUND(COUNT(tab2.player_id)/COUNT(tab1.player_id), 2) AS fraction
FROM (SELECT player_id, MIN(event_date) first_log -- 유저별 첫번째 접속일
FROM Activity
GROUP BY player_id) tab1
LEFT JOIN Activity tab2
ON tab1.player_id = tab2.player_id
AND tab1.first_log = tab2.event_date - 1
# 2
SELECT ROUND(COUNT(DISTINCT player_id) / (SELECT COUNT(DISTINCT player_id)
FROM Activity)
,2) as fraction -- 둘째 자리 반올림
FROM Activity
WHERE (player_id, DATE_SUB(event_date, INTERVAL 1 DAY)) IN -- 로그인한 날짜 하루 전날이 첫번쨰 접속일이면
(SELECT player_id, MIN(event_date) as first_login -- 첫번째 접속일
FROM Activity
GROUP BY player_id)
시간, 날짜 빼기
DATE_SUB(기준 날짜, INTERVAL 1 day)
'🛠️Skill > CodingTest' 카테고리의 다른 글
[leetcode] 1204. Last Person to Fit in the Bus / 버스 마지막 승객 구하기 (0) | 2023.03.09 |
---|---|
[leetcode] 1174. Immediate Food Delivery II / 즉시배송할 수 있는 주문비율 (0) | 2023.03.08 |
[leetcode] 1164. Product Price at a Given Date / 지정 날짜에 변경된 데이터 조회 / UNION (0) | 2023.02.17 |
[leetcode] 577. Employee Bonus / COALESCE (0) | 2023.01.15 |
[leetcode] 1158. Market Analysis I / CASE WHEN, IFNULL (0) | 2022.12.30 |
댓글