Skip to content

2720. Popularity Percentage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
WITH
  TwoWayFriends AS (
    SELECT user1, user2 FROM Friends
    UNION ALL
    SELECT user2, user1 FROM Friends
  )
SELECT
  user1,
  ROUND(
    100 * (COUNT(DISTINCT user2) / (COUNT(*) OVER())),
    2
  ) AS percentage_popularity
FROM TwoWayFriends
GROUP BY 1
ORDER BY 1;