티스토리 뷰

https://leetcode.com/problems/game-play-analysis-iv

 

Game Play Analysis IV - LeetCode

Can you solve this real interview question? Game Play Analysis IV - Table: Activity +--------------+---------+ | Column Name | Type | +--------------+---------+ | player_id | int | | device_id | int | | event_date | date | | games_played | int | +---------

leetcode.com

with cond as (
    select
        distinct player_id
        , datediff(lead(event_date, 1) over (partition by player_id order by event_date), min(event_date) over (partition by player_id)) cond
    from Activity
    order by player_id, event_date
)
select
    round(count(distinct c.player_id)/count(distinct a.player_id), 2) as fraction
from Activity a
left join cond c on a.player_id = c.player_id
    and c.cond = 1

'프로그래밍연습 > SQL' 카테고리의 다른 글

[SQL]exchange-seats  (0) 2023.08.21
[SQL]friend-requests-ii-who-has-the-most-friends  (0) 2023.08.20
[SQL]human-traffic-of-stadium  (0) 2023.08.18
[SQL]trips-and-users  (0) 2023.08.18
[SQL]employees-earning-more-than-their-managers  (0) 2023.08.17
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함