코딩테스트 SQL 코드카타 (Followers count)

2024. 12. 6. 09:23·Daily 코드카타/SQL

문제

Find Followers Count - LeetCode

 

Write a solution that will, for each user, return the number of followers.

Return the result table ordered by user_id in ascending order.

The result format is in the following example.

 

Example 1:

Input: 
Followers table:
+---------+-------------+
| user_id | follower_id |
+---------+-------------+
| 0       | 1           |
| 1       | 0           |
| 2       | 0           |
| 2       | 1           |
+---------+-------------+
Output: 
+---------+----------------+
| user_id | followers_count|
+---------+----------------+
| 0       | 1              |
| 1       | 1              |
| 2       | 2              |
+---------+----------------+
Explanation: 
The followers of 0 are {1}
The followers of 1 are {0}
The followers of 2 are {0,1}

풀이

  1. user_id 당 follower_id 카운트
  2. user_id 그룹화
  3. user_id 기준오름정렬

코드

select user_id, count(follower_id) as followers_count
from Followers
group by user_id
order by user_id

 


링크

LeetCode/1729-find-followers-count at main · K-MarkLee/LeetCode

 

LeetCode/1729-find-followers-count at main · K-MarkLee/LeetCode

Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub](https://github.com/QasimWani/LeetHub) - K-MarkLee/LeetCode

github.com

 

저작자표시 비영리 변경금지 (새창열림)

'Daily 코드카타 > SQL' 카테고리의 다른 글

코딩테스트 SQL 코드카타 (Primary Department)  (1) 2024.12.10
코딩테스트 SQL 코드카타 (Number of Employees)  (1) 2024.12.09
코딩테스트 SQL 코드카타 (Student more than 5)  (0) 2024.12.05
코딩테스트 SQL 코드카타 (Percentage of Users)  (1) 2024.11.27
코딩테스트 SQL 코드카타 (Project Employees)  (0) 2024.11.26
'Daily 코드카타/SQL' 카테고리의 다른 글
  • 코딩테스트 SQL 코드카타 (Primary Department)
  • 코딩테스트 SQL 코드카타 (Number of Employees)
  • 코딩테스트 SQL 코드카타 (Student more than 5)
  • 코딩테스트 SQL 코드카타 (Percentage of Users)
코드 유랑자 승열
코드 유랑자 승열
코드 유랑자 승열의 프로그래밍 일지를 남기는 공간입니다.
  • 코드 유랑자 승열
    승열의 프로그래밍 시네마
    코드 유랑자 승열
  • 전체
    오늘
    어제
  • 링크

    • 깃허브 보러가기
    • 링크드인 보러가기
    • 인스타그램 보러가기
    • 카테고리
      • 코딩테스트
        • BaekJoon
      • TIL and WIL
        • TIL
        • WIL
      • 주말스터디
      • 내일배움캠프
        • 사전캠프 강의 (SQL)
      • 용어정리
        • Python
        • Python-Library
        • Machine-Learning
        • Deep-Learning
        • AI 활용
        • LLM & RAG
        • Docker
        • Django
        • SQL
        • Java Script
        • etc
      • Daily 코드카타
        • SQL
        • Python 알고리즘
      • 임시저장
      • 보류
  • 태그

    vector db
    langchain
    티스토리챌린지
    llm
    template
    django
    오블완
    word2vec
    View
    RAG
  • 인기 글

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.1
코드 유랑자 승열
코딩테스트 SQL 코드카타 (Followers count)
상단으로

티스토리툴바