Image Alt photo_exhibition

Write a solution to find the first login date for each player.

Return the result table in any order.

The result format is in the following example.

Image Alt photo_exhibition

플레이어 아이디별로 처음 로그인 한 date를 뽑는 문제이다. 내가 접근한 방식은 먼저 ROW_NUMBER 함수를 통해서 순위를 매겨주는 것이다. PARTITION BY로 player_id 별로 묶어 event_date가 빠른 순으로 순위를 매겼다. 그 다음에 순위가 1인 조건을 붙여 최종 결과 값을 뽑았다.

SELECT DISTINCT player_id
               ,event_date AS first_login
FROM (
   SELECT *
        ,ROW_NUMBER () OVER (PARTITION BY player_id ORDER BY event_date) AS login_n
    FROM Activity
) Activity_first
WHERE login_n = 1 -- 순위가 1인!