반응형
https://leetcode.com/problems/find-total-time-spent-by-each-employee/description/
group by를 사용해본 문제였습니다.
📕 풀이방법
📔 풀이과정
aggregation 함수 내에 수식이 들어갈 수 있습니다.employees table에서 event_day, emp_ud, out_time - in_time 의 합 을 event_day, emp_id에 대해 group화해 select해줍니다.* Oracle은 ''YYYY-MM-DD 00:00:00" 형식이므로 TO_CHAR로 정답에 맞게 total_time을 가공해줍니다.
📕 Code
📔 MySQL
select event_day as day, emp_id, sum(out_time - in_time) as total_time
from employees
group by event_day, emp_id
📔 Oracle
select TO_CHAR(event_day, 'YYYY-MM-DD') as day, emp_id, sum(out_time - in_time) as total_time
from employees
group by event_day, emp_id
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'SQL' 카테고리의 다른 글
(SQL) - LeetCode (easy) 1789. Primary Department for Each Employee (0) | 2024.07.31 |
---|---|
(SQL) - LeetCode (easy) 1757. Recyclable and Low Fat Products (0) | 2024.07.18 |
(SQL) - LeetCode (easy) 1729. Find Followers Count (0) | 2024.06.23 |
(SQL) - LeetCode (easy) 1693. Daily Leads and Partners (0) | 2024.06.13 |
(SQL) - LeetCode (easy) 1683. Invalid Tweets (0) | 2024.06.07 |