[ORACLE_SQL](Leet_Code)1633. Percentage of Users Attended a Contest

이경영·2023년 7월 28일
0

오라클

목록 보기
34/43

https://leetcode.com/problems/percentage-of-users-attended-a-contest/?envType=study-plan-v2&envId=top-sql-50

문제요약

콘테스트에 참여한 user수 / 총 user수 를 구하여라!

문제포인트

테이블별 각 user수를 구하는 공식은 count(user_id 혹은 *) from 테이블 이라는 것은 알지만 sql로 푸려고하면 난감하고 헷갈린다..

생각정리가 가장 중요한것 같다.

정답

서브쿼리를 이용한 풀이

select contest_id, 
        round((count(a.contest_id)/(select count(*) from users))*100,2) percentage  
        from Register a 
group by contest_id 
order by percentage desc, contest_id asc;
profile
꾸준히

1개의 댓글

comment-user-thumbnail
2023년 7월 28일

잘 읽었습니다. 좋은 정보 감사드립니다.

답글 달기