inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

174만명의 커뮤니티!! 함께 토론해봐요.

고급반 서브쿼리 해커랭크 challenges 문제 질문

미해결

[백문이불여일타] 데이터 분석을 위한 고급 SQL

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. 해설에서는 count(*)를 사용했는데 count( challenge_id)를 사용하면 왜 값이 다른지 이해가 잘 되지 않습니다. 부연 설명으로 max(challenge_id)를 하면 50이 나오게 되어 같은 원리로 select hacker_id, count(challenge_id) as cnt from challenges group by hacker_id ) as suq_t2 group by cnt having count(challenge_id) = 1 을 하게 되면 hacker_id 당 카운트가 1번인 걸 뜻하는 걸로 나올 거라 예상했는데 횟수가 1번인 것만 나오게 되네요. select hacker_id, count(challenge_id) as cnt from challenges group by hacker_id ) as suq_t2 group by cnt having count(cnt) = 1 아래는 쿼리 전문을 첨부합니다. /* Enter your query here. */ select h.hacker_id ,h.name ,count(challenge_id) as cnt from Hackers as h inner join Challenges as c on h.hacker_id = c.hacker_id group by h.hacker_id,h.name having cnt in ( select max(cnt) from ( select hacker_id, count(challenge_id) as cnt from challenges group by hacker_id) as suq_t1) or cnt in ( select cnt from ( select hacker_id, count(challenge_id) as cnt from challenges group by hacker_id ) as suq_t2 group by cnt having count(challenge_id) = 1 ) order by 3 desc , 1 asc

  • 고급반
  • sql
Busantist 댓글 1 좋아요 1 조회수 248

인기 태그

인프런 TOP Writers

주간 인기글