지난 공부기록/알고리즘 풀이

SQL - Algorithm #7

hkl22 2024. 6. 19. 10:07

SQL Algorithm

LeetCode

1741. Find Total Time Spent by Each Employee

Column Name Type
emp_id int
event_day date
in_time int
out_time int
  • (emp_id, event_day, in_time) is the primary key (combinations of columns with unique values) of this table.
  • The table shows the employees' entries and exits in an office.
  • event_day is the day at which this event happened, in_time is the minute at which the employee entered the office, and out_time is the minute at which they left the office.
  • in_time and out_time are between 1 and 1440.
  • It is guaranteed that no two events on the same day intersect in time, and in_time < out_time.
  • Write a solution to calculate the total time in minutes spent by each employee on each day at the office. Note that within one day, an employee can enter and leave more than once. The time spent in the office for a single entry is out_time - in_time.
  • Return the result table in any order.
SELECT event_day AS day, emp_id, SUM(out_time - in_time) AS total_time
FROM Employees
GROUP BY event_day, emp_id;

1693. Daily Leads and Partners

Column Name Type
date_id date
make_name varchar
lead_id int
partner_id int
  • There is no primary key (column with unique values) for this table. It may contain duplicates.
  • This table contains the date and the name of the product sold and the IDs of the lead and partner it was sold to.
  • The name consists of only lowercase English letters.
  • For each date_id and make_name, find the number of distinct lead_id's and distinct partner_id's.
  • Return the result table in any order.
SELECT date_id, make_name, COUNT(DISTINCT lead_id) AS unique_leads, COUNT(DISTINCT partner_id) AS unique_partners
FROM DailySales
GROUP BY date_id, make_name;

https://leetcode.com/problems/find-total-time-spent-by-each-employee/

https://leetcode.com/problems/daily-leads-and-partners/

'지난 공부기록 > 알고리즘 풀이' 카테고리의 다른 글

SQL - Algorithm #9  (0) 2024.06.21
SQL - Algorithm #8  (0) 2024.06.20
Python - Algorithm #6  (0) 2024.06.18
Python - Algorithm #5  (0) 2024.06.17
Python - Algorithm #4  (0) 2024.06.12