- 2019년 2019-01-01 and 2019-03-31에만 팔린 상품을 출력하라
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'
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');