반응형

sql 실력 향상을 위해 돈을 내고 리트코드를 풀고 있는데, count over partion by 내용이 나와서 올려본다.

 

직원이 속한 팀의 인원수 찾기

-> 유저 Id와 소속 팀 Id가 있는 테이블을 이용해서, 유저별로 속한 팀의 인원수를 알아내기.

키워드 : window function , count over partition by , sql 팀사이즈 찾기

 

 

1303. Find the Team Size

Write an SQL query to find the team size of each of the employees.

Return result table in any order.

The query result format is in the following example.

 

해답

select employee_id, count(employee_id) over (partition by team_id) as team_size
from Employee

어렵게 생각하지 말고 쉽게 생각하면 한줄로 해결되는 문제. Mysql 기반이다. 

반응형

+ Recent posts