2019년 1 분기에만 팔린 제품들을 알아보자.
join 해서 날짜 필터링 해주면 된다. distinct 안 넣었다가 틀렸다.
select distinct(p.product_id), (p.product_name)
from Product as p join
sales as s on p.product_id = s.product_id
where s.product_id not in (select distinct(product_id)
from sales
where sale_date < date("2019-01-01") or
sale_date > date("2019-03-31"))
and
s.sale_date >= date("2019-01-01") and
s.sale_date <= date("2019-03-31") ;
'learning > SQL' 카테고리의 다른 글
[LeetCode 1141] User Activity for the Past 30 Days I (0) | 2023.01.31 |
---|---|
[LeetCode 607] Sales Person (0) | 2023.01.30 |
[LeetCode 197] Rising Temperature (0) | 2023.01.30 |
[LeetCode 1158] Market Analysis I (1) | 2023.01.29 |
[LeetCode 1393] Capital Gain/Loss (0) | 2023.01.29 |
댓글