https://leetcode.com/problems/find-total-time-spent-by-each-employee/
group by 로 그룹이 된 rows 를 대상으로, 집계 함수 사용이 가능함을 볼 수 있다.
sum 은 하나의 결과만 도출하기 때문에, group by 를 사용한 상태에서 sum 결과를 select 하는 것이 가능하다.
select event_day as day, emp_id, sum(out_time-in_time) as total_time
from Employees
group by event_day, emp_id
< English (feedback by ChatGPT) >
We can use transaction functions for grouped rows by 'group by'.
(We can apply aggregate functions to the rows grouped by a GROUP BY clause.
'sum' puts only one result, so it's possible to select a result of sum on group by.
(Since SUM returns a single result per group, it can be used in a SELECT statement alongside GROUP BY.)
'Coding Interview' 카테고리의 다른 글
[leetcode] 1378. Replace Employee ID With The Unique Identifier (0) | 2025.05.12 |
---|---|
[leetcode] 1795. Rearrange Products Table (0) | 2025.05.10 |
[leetcode] 2356. Number of Unique Subjects Taught by Each Teacher (1) | 2025.05.10 |
[leetcode] 160. Intersection of Two Linked Lists (0) | 2025.05.10 |
[leetcode] 141. Linked List Cycle (0) | 2025.05.09 |