[LeetCode/SQL] 1084. Sales Analysis III

Sooyeon·2023년 11월 13일
0

문제풀이 

목록 보기
34/95
post-thumbnail

[LeetCode/SQL]


📌 1084. Sales Analysis III

문제

풀이

- 2019년 2019-01-01 and 2019-03-31에만 팔린 상품을 출력하라 

방법 I

GROUP BY , MAX/MIN 사용하기

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

방법 II

SUBQUERY , BETWEEN 사용하기

SELECT product_id,product_name 
FROM product
WHERE product_id NOT IN (SELECT product_id 
                          FROM sales
                          WHERE sale_date NOT BETWEEN '2019-01-01' and '2019-03-31');

0개의 댓글