title: Window function query issue?
body: <p>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.</p>
  <p>The query result format is in the following example.</p>
  <pre><code>Example 1:
  
  Input: 
  Activity table:
  +-----------+-----------+------------+--------------+
  | player_id | device_id | event_date | games_played |
  +-----------+-----------+------------+--------------+
  | 1         | 2         | 2016-03-01 | 5            |
  | 1         | 2         | 2016-03-02 | 6            |
  | 2         | 3         | 2017-06-25 | 1            |
  | 3         | 1         | 2016-03-02 | 0            |
  | 3         | 4         | 2018-07-03 | 5            |
  +-----------+-----------+------------+--------------+
  Output: 
  +-----------+
  | fraction  |
  +-----------+
  | 0.33      |
  +-----------+
  Explanation: 
  Only the player with id 1 logged back in after the first day he had logged in so the answer is 1/3 = 0.33
  </code></pre>
  <p>When using this query <a href="https://leetcode.com/problems/game-play-analysis-iv/" rel="nofollow noreferrer">this leetcode</a> problem is passing all test cases:</p>
  <pre><code>WITH temp AS(
      SELECT player_id,
      event_date - LAG(event_date, 1) OVER (PARTITION BY player_id ORDER BY event_date) AS difference, 
      RANK() OVER (PARTITION BY player_id ORDER BY event_date) as rn
      FROM activity
  ),
  
  tp AS
  (
      SELECT count(distinct(player_id)) as all_players
      FROM activity
  )
  
  SELECT ROUND(count(t.player_id)/tp.all_players,2) AS fraction
  
      FROM temp t
      JOIN tp
  
  WHERE t.rn = 2
  AND t.difference = 1
  </code></pre>
  <p>When I use this below query it's not working for all test cases can anyone tell me why this is not working where above one is working:</p>
  <pre><code>WITH temp AS(
      SELECT DISTINCT(player_id), difference FROM
      (SELECT player_id, event_date - LAG(event_date, 1) OVER (PARTITION BY player_id ORDER BY event_date) AS difference FROM activity) x WHERE x.difference = 1
  ),
  
  tp AS
  (
      SELECT count(distinct(player_id)) as all_players
      FROM activity
  )
  
  SELECT ROUND(COUNT(*)/tp.all_players, 2) as fraction FROM temp, tp;
  </code></pre>