Skip to content

Commit 3cddf8b

Browse files
committed
task: #1633
1 parent da9b808 commit 3cddf8b

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Have a good contributing!
5151
- [1407. Top Travellers](./leetcode/easy/1407.%20Top%20Travellers.sql)
5252
- [1484. Group Sold Products By The Date](./leetcode/easy/1484.%20Group%20Sold%20Products%20By%20The%20Date.sql)
5353
- [1587. Bank Account Summary II](./leetcode/easy/1587.%20Bank%20Account%20Summary%20II.sql)
54+
- [1633. Percentage of Users Attended a Contest](./leetcode/easy/1633.%20Percentage%20of%20Users%20Attended%20a%20Contest.sql)
5455
- [1693. Daily Leads and Partners](./leetcode/easy/1693.%20Daily%20Leads%20and%20Partners.sql)
5556
- [1729. Find Followers Count](./leetcode/easy/1729.%20Find%20Followers%20Count.sql)
5657
- [1741. Find Total Time Spent by Each Employee](./leetcode/easy/1741.%20Find%20Total%20Time%20Spent%20by%20Each%20Employee.sql)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Question 1633. Percentage of Users Attended a Contest
3+
Link: https://leetcode.com/problems/percentage-of-users-attended-a-contest/
4+
5+
Table: Users
6+
7+
+-------------+---------+
8+
| Column Name | Type |
9+
+-------------+---------+
10+
| user_id | int |
11+
| user_name | varchar |
12+
+-------------+---------+
13+
user_id is the primary key (column with unique values) for this table.
14+
Each row of this table contains the name and the id of a user.
15+
16+
17+
Table: Register
18+
19+
+-------------+---------+
20+
| Column Name | Type |
21+
+-------------+---------+
22+
| contest_id | int |
23+
| user_id | int |
24+
+-------------+---------+
25+
(contest_id, user_id) is the primary key (combination of columns with unique values) for this table.
26+
Each row of this table contains the id of a user and the contest they registered into.
27+
28+
29+
Write a solution to find the percentage of the users registered in each contest rounded to two decimals.
30+
31+
Return the result table ordered by percentage in descending order. In case of a tie, order it by contest_id in ascending order.
32+
*/
33+
34+
SELECT
35+
contest_id,
36+
ROUND(COUNT(contest_id) * 1.0 / (SELECT COUNT(u.user_id) FROM Users AS u) * 100, 2) AS percentage
37+
FROM Register
38+
GROUP BY contest_id
39+
ORDER BY percentage DESC, contest_id ASC

0 commit comments

Comments
 (0)