bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1633. Percentage of Users Attended a Contest

1633. Percentage of Users Attended a Contest

Leetcode Solutions

Calculating User Registration Percentages by Contest

  • Count the number of unique users registered for each contest using COUNT(DISTINCT user_id) within the Register table.
  • Calculate the total number of users in the Users table using SELECT COUNT(user_id) FROM Users.
  • Divide the count of registered users for each contest by the total number of users to get the fraction of users registered for that contest.
  • Multiply the fraction by 100 to convert it to a percentage.
  • Use the ROUND function to round the percentage to two decimal places.
  • Group the results by contest_id using GROUP BY.
  • Order the results by the calculated percentage in descending order using ORDER BY percentage DESC.
  • In case of a tie in percentages, order by contest_id in ascending order using ORDER BY contest_id.
erDiagram
    Users {
        int user_id PK
        varchar user_name
    }
    Register {
        int contest_id PK
        int user_id PK
    }
    Users ||--o{ Register : registers

Using a Variable to Store Total User Count

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...