You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
select product_id, 10 price from Products where product_id not in (
select product_id from Products where change_date<='2019-08-16'
)
unionselect product_id, new_price price from Products where (product_id, change_date) in (
select product_id, max(change_date) datefrom Products where change_date<='2019-08-16'group by product_id
)
Solution v2
selectp1.product_id, ifnull(p2.new_price, 10) as price from (
select distinct product_id from products
) as p1
left join
(
select product_id, new_price from products where (product_id, change_date) in (
select product_id, max(change_date) as max_date from products
where change_date <='2019-08-16'group by product_id
)
) as p2 onp1.product_id=p2.product_id