LeetCode - 1633. Percentage of Users Attended a Contest (MySQL)

조민수·2024년 6월 13일
0

LeetCode

목록 보기
34/61

Easy, SQL - 계산

RunTime : 1257 ms


문제

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.

The result format is in the following example.


풀이

  • 해당 값을 선택한 인원 수/전체 인원 수를 계산해야 했던 문제
  • 프로그래머스 Lv3 ~ Lv4 되지 않을까 싶다.
SELECT contest_id,
ROUND(COUNT(DISTINCT user_id) / (SELECT COUNT(*) FROM Users) * 100 ,2) as percentage
FROM Register
GROUP BY 1
ORDER BY 2 desc, 1
profile
사람을 좋아하는 Front-End 개발자

0개의 댓글