这里仅提供一个思路,虽然笨但有效
其实这题只有一个限制,只能在2019-01-01到2019-03-31出售过,但是这也足够让人头痛了
基本思路如下:
一、取出在非限制时间段内出售过商品的id 和 name,过一个distinct
二、在Product表中匹配,匹配成功的则不是我们想要的
三、在匹配不成功的里边寻找 id存在于Sales表中的
select
A1.product_id
,product_name
from
Product as A1
left join
(
select
distinct
T1.product_id
from Product as T1
left join Sales as T2
on T1.product_id = T2.product_id
where sale_date not between '2019-01-01' and '2019-03-31'
) A2
on A1.product_id = A2.product_id
where A2.product_id is null and A1.product_id in
(
select
distinct
product_id
from Sales
)
group by 1,2