LeetCode - 1084. Sales Analysis III (MySQL)

조민수·2024년 7월 24일
0

LeetCode

목록 보기
55/61

Easy, SQL - SELECT

RunTime : 1190 ms


문제

Write a solution to report the products that were only sold in the first quarter of 2019. That is, between 2019-01-01 and 2019-03-31 inclusive.

Return the result table in any order.

The result format is in the following example.


풀이

  • AND 전까지 2019의 1분기로 나누고, AND 이후로 only 조건을 맞춘다.
  • Easy 치고는 쿼리문이 조금은 복잡했다고 생각....
SELECT S.product_id, P.product_name FROM Product as P JOIN Sales as S
ON P.product_id = S.product_id
WHERE S.sale_date BETWEEN '2019-01-01' AND '2019-03-31'
AND S.product_id NOT IN
(
	SELECT product_id FROM Sales
	WHERE sale_date > '2019-03-31' OR sale_date < '2019-01-01'
)
GROUP BY 1, 2
profile
사람을 좋아하는 Front-End 개발자

0개의 댓글