LeetCode_Study_Plan/SQL
1741. Find Total Time Spent by Each Employee mysql
개발하는루루
2022. 10. 2. 15:13
https://leetcode.com/problems/find-total-time-spent-by-each-employee/?envType=study-plan&id=sql-i
Find Total Time Spent by Each Employee - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
select tb.event_day as day, tb.emp_id as emp_id, sum(diff_time) as total_time
from (select event_day, emp_id, out_time - in_time as diff_time from employees) tb group by 1, 2;
속도가 넘 후지길래.. 다른 예시 답안도 좀 찾아봤더니
그냥 서브쿼리 없이 해도 되었다.
ㅎ_ㅎ
아래는 예시코드이다.
SELECT event_day AS day, emp_id, SUM(out_time - in_time) AS total_time
FROM Employees
GROUP BY event_day, emp_id;
출처 : https://github.com/everthis/leetcode-js/blob/master/1741-find-total-time-spent-by-each-employee.sql