-
leetcode - DescriptionSolutionDiscuss (49)Submissions2298. Tasks Count in the WeekendSQL 문제풀이 2022. 9. 19. 15:38
난이도 : Medium
Table: Tasks
+-------------+------+ | Column Name | Type | +-------------+------+ | task_id | int | | assignee_id | int | | submit_date | date | +-------------+------+ task_id is the primary key for this table. Each row in this table contains the ID of a task, the id of the assignee, and the submission date.
Write an SQL query to report:
- the number of the tasks that were submitted during the weekend (Saturday, Sunday) as weekend_cnt, and
- the number of the tasks that were submitted during the working days as working_cnt.
Return the result table in any order.
The query result format is shown in the following example.
Example 1:
Input: Tasks table: +---------+-------------+-------------+ | task_id | assignee_id | submit_date | +---------+-------------+-------------+ | 1 | 1 | 2022-06-13 | | 2 | 6 | 2022-06-14 | | 3 | 6 | 2022-06-15 | | 4 | 3 | 2022-06-18 | | 5 | 5 | 2022-06-19 | | 6 | 7 | 2022-06-19 | +---------+-------------+-------------+ Output: +-------------+-------------+ | weekend_cnt | working_cnt | +-------------+-------------+ | 3 | 3 | +-------------+-------------+ Explanation: Task 1 was submitted on Monday. Task 2 was submitted on Tuesday. Task 3 was submitted on Wednesday. Task 4 was submitted on Saturday. Task 5 was submitted on Sunday. Task 6 was submitted on Sunday. 3 tasks were submitted during the weekend. 3 tasks were submitted during the working days.
WITH sub AS ( SELECT task_id , assignee_id , WEEKDAY(submit_date) day FROM Tasks ) SELECT COUNT(CASE WHEN day BETWEEN 5 AND 6 THEN task_id END) weekend_cnt , COUNT(CASE WHEN day BETWEEN 0 AND 4 THEN task_id END) working_cnt FROM sub
Accepted (74.86%)
'SQL 문제풀이' 카테고리의 다른 글
leetcode -2308. Arrange Table by Gender (0) 2022.09.20 leetcode - 1767. Find the Subtasks That Did Not Execute (0) 2022.09.20 leetcode - DescriptionSolutionDiscuss (50)Submissions2292. Products With Three or More Orders in Two Consecutive Years (0) 2022.09.19 leetcode -2238. Number of Times a Driver Was a Passenger (0) 2022.09.19 leetcode - 1635. Hopper Company Queries I (0) 2022.09.16