一题多解,体会思路

1084. 销售分析III - 力扣(LeetCode)

           Product                      Sales

 编写一个SQL查询,报告2019年春季才售出的产品。即2019-01-012019-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')

 

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页