[SQL문제풀기] Product Price at a Given Date

silver's avatar
Nov 10, 2025
[SQL문제풀기] Product Price at a Given Date
Contents
문제MySQL

문제

MySQL

내가 작성한 오답

: 가격이 오르는 경우만 생각했다
select i.product_id, ifnull(p.price, 10) price from (select product_id, max(new_price) price from Products where date_format(change_date,'%Y-%m-%d') <= '2019-08-16' group by product_id) p right join (select distinct product_id from Products) i on p.product_id = i.product_id;

내가 작성한 정답

with a as(select product_id, new_price price from Products p where (p.product_id, p.change_date) in (select product_id, max(change_date) from Products where date_format(change_date,'%Y-%m-%d') <= '2019-08-16' group by product_id)) select product_id, price from a union all select distinct product_id, 10 price from Products where product_id not in (select product_id from a);
Share article

silver