문제
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}
풀이
- user_id 당 follower_id 카운트
- user_id 그룹화
- 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 |