Leetcode SQL50 (1729)

Pocketopi·2025년 4월 14일

[MYSQL] Leetcode

목록 보기
3/34
post-thumbnail

🔔 문제

LeetCode - Find Followers Count(https://leetcode.com/problems/find-followers-count/description/?envType=study-plan-v2&envId=top-sql-50)
➔ 각 사용자별로 팔로워 수를 출력하라.

🎯 풀이방법

핵심

GROUP BY를 사용하여 USER_ID별로 그룹화하고,
COUNT()를 사용하여 각 사용자에 대한 팔로워 수를 계산한다.

💻 전체 코드

SELECT USER_ID, COUNT(*) AS FOLLOWERS_COUNT
FROM FOLLOWERS
GROUP BY USER_ID
ORDER BY USER_ID

💡 핵심문법 및 배운점

  • GROUP BY / ORDER BY를 여태 1,2 이런식으로 INDEX를 이용했는데
    그렇게 하면 처리속도가 더욱 느리다.
profile
통계학/컴퓨터공학 전공 4학년 학생 DA뿌수기 일기장

0개의 댓글