Product Sales
编写一个SQL查询,报告2019年春季才售出的产品。即仅在2019-01-01至2019-03-31(含)之间出售的商品。
从正面出发写:
select p.product_id,p.product_name
from product p, sales s
where p.product_id = s.product_id
group by p.product_id
having max(s.sale_date) <='2019-03-31'
and min(s.sale_date)>= '2019-01-01'
从反面出发写:
select p.product_id,p.product_name
from product p, sales s
where p.product_id = s.product_id
group by p.product_id
having sum(sale_date < '2019-01-01')=0
and sum(sale_date>'2019-03-31')=0;
select distinct p.product_id, p.product_name
from sales s, product p
where s.product_id = p.product_id
and s.product_id not in
(select product_id
from sales
where sale_date not between '2019-01-01' and '2019-03-31')