First we'll see a wrong one and explanation then we'll see a right one ;-)
# Write your MySQL query statement below
select r.contest_id, round(count(distinct r.user_id)*100/count(user_id), 2) percentage
from Register r left join Users u
on u.user_id=r.user_id group by r.contest_id ORDER BY percentage DESC, contest_id
Why wrong:
The dividend (or the denominator) is wrong. It is not the User
table's countnumber but the new table's.
# Write your MySQL query statement below
select r.contest_id, round(count(distinct r.user_id)*100/(select count(user_id) from Users), 2) percentage
from Register r left join Users u
on u.user_id=r.user_id group by r.contest_id ORDER BY percentage DESC, contest_id
- 2024.06.02