1164. 指定日期的产品价格
题目链接:1164. 指定日期的产品价格
代码如下:
# Write your MySQL query statement below
select p1.product_id,ifnull(new_price,10) as price
from (select distinct product_idfrom Products
)as p1 -- 所有的产品
left join(select product_id,new_pricefrom Productswhere (product_id,change_date) in (select product_id,max(change_date)from Productswhere change_date <= '2019-08-16'group by product_id)
)as p2 -- 在 2019-08-16 之前有过修改的产品和最新的价格
on p1.product_id=p2.product_id