본문 바로가기
취준/코팅 테스트

[LeetCode] 1084. Sales Analysis 3

by 소복소복뚜벅뚜벅 2024. 4. 10.

문제 

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.

 

"2019년 1분기에만 판매된 제품을 알 수 있는 쿼리를 작성해라 즉, 2019-01-01 부터 2019-03-01 사이에 포함된다." 

 

문제 풀이 

 

product_id 별로 날짜를 확인 해야 한다. 이때 중요하건 product_id 모두가 1분기 날짜에 팔려야 한다. 즉, 1개라도 1분기 날자 이후에 판매된 경우는 제외되어야 한다. 

 

SELECT s.product_id
     , p.product_name
FROM Sales AS s 
LEFT JOIN Product AS p ON s.product_id = p.product_id 
GROUP BY s.product_id 
HAVING MIN(s.sale_date) >= '2019-01-01' AND MAX(s.sale_date)<='2019-03-31'