1164.sql (342B)
1 SELECT DISTINCT product_id, 10 AS 'price' 2 FROM Products 3 GROUP BY product_id 4 HAVING MIN(change_date) > "2019-08-16" 5 UNION ALL 6 SELECT product_id, new_price 7 FROM Products 8 WHERE (product_id, change_date) IN ( 9 SELECT product_ID, MAX(change_date) as recent_date 10 FROM Products 11 WHERE change_date <= "2019-08-16" 12 GROUP BY product_id 13 )