안녕하세요!
이번 포스팅은 LeetCode에 있는 Percentage of Users Attended a Contest 문제를 OracleDB로 풀어보려고 합니다!
(모든 문제는 Oracle로 풀이하겠습니다.)
1. 문제 링크 : https://leetcode.com/problems/percentage-of-users-attended-a-contest/description/
2. 문제
| Column name | Type |
| user_id | int |
| user_name | varchar |
| Column name | Type |
| contest_id | int |
| user_id | int |
[문제] 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.
각 콘테스트에 등록된 사용자의 비율을 조회하는 문제입니다.
3. 제출 쿼리 및 설명
최종) 각 콘테스트에 등록된 사용자의 비율을 조회합니다.
SELECT CONTEST_ID, ROUND(COUNT(DISTINCT R.USER_ID) / (SELECT COUNT(USER_ID)
FROM USERS)*100, 2) AS percentage
FROM USERS U, REGISTER R
WHERE U.USER_ID = R.USER_ID
GROUP BY CONTEST_ID
ORDER BY PERCENTAGE DESC, CONTEST_ID ASC
;
'SQL > LeetCode' 카테고리의 다른 글
| [SQL] Fix Names in a Table(LeetCode/Oracle) (0) | 2023.10.26 |
|---|---|
| [SQL] Average Time of Process per Machine(LeetCode/Oracle) (0) | 2023.10.26 |
| [SQL] Bank Account Summary II(LeetCode/Oracle) (0) | 2023.10.26 |
| [SQL] Patients With a Condition(LeetCode/Oracle) (0) | 2023.10.26 |
| [SQL] Group Sold Products By The Date(LeetCode/Oracle) (0) | 2023.10.26 |