CREATE VIEW prices_extra AS SELECT product, price, date_start, LEAD(date_start) OVER(PARTITION BY product ORDER BY date_start) next_date FROM prices;
CREATE TABLE revenue AS SELECT sales.product, sales.date, prices_extra.price * sales.amount AS revenue FROM sales INNER JOIN
prices_extra ON sales.product = prices_extra.product WHERE
CASE WHEN prices_extra.next_date IS NOT NULL
THEN prices_extra.date_start <= sales.date AND sales.date < prices_extra.next_date
ELSE sales.date > prices_extra.date_start END;