1084. 销售分析III
编写一个SQL查询,报告2019年春季才售出的产品。即仅在2019-01-01至2019-03-31(含)之间出售的商品。
以任意顺序返回结果表。
查询结果格式如下所示。
题解:
方法1:
select p.product_id, p.product_name
from Product p
left join Sales s on p.product_id=s.product_id
group by p.product_id,p.product_name
having min(sale_date)>="2019-01-01" and max(sale_date)<="2019-03-31"
方法2:
select p.product_id, p.product_name
from Product p,Sales s
where p.product_id=s.product_id
group by p.product_id,p.product_name
having sum(sale_date<"2019-01-01")=0 and sum(sale_date>"2019-03-31")=0