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.)

+ Recent posts