Leetcode PostgreSQL Sales Analysis III
업데이트:
문제
코드
-- Write your PostgreSQL query statement below
SELECT Product.product_id, Product.product_name
FROM Product
WHERE EXISTS (
SELECT 1 FROM Sales
WHERE Sales.sale_date BETWEEN '2019-01-01' AND '2019-03-31'
AND Sales.product_id = Product.product_id
)
AND NOT EXISTS (
SELECT 1 FROM Sales
WHERE Sales.sale_date NOT BETWEEN '2019-01-01' AND '2019-03-31'
AND Sales.product_id = Product.product_id
)
결과
설명
- Product 중 2019년 1분기(2019-01-01 ~ 2019-03-31)에만 판매된 품목의 product_id와 product_name을 찾는 문제이다.
댓글남기기