[코드카타] SQL 33 Percentage of Users Attended a Contest

Data_Student·2024년 11월 15일
0

코드카타

목록 보기
42/57

[코드카타] SQL 33 Percentage of Users Attended a Contest

33. Percentage of Users Attended a Contest
https://leetcode.com/problems/percentage-of-users-attended-a-contest/submissions/1453048443/

Write a solution to find the percentage of the users registered in 
each contest rounded to two decimals.
Return the result table ordered by percentage in descending order. 
In case of a tie, order it by contest_id in ascending order.
select contest_id, 
       round((count(R.user_id)/(select count(*) from users))*100,2) percentage
from Users U join Register R on U.user_id = R.user_id
group by contest_id
order by 2 desc, 1

0개의 댓글