Problems / Price As-Of Order Time / Editorial
orders ⋈ price_history
effective_from <= order_time
ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY effective_from DESC)
rn = 1
unit_price * quantity
Effective-dated tables (prices, tax rates, exchange rates, SCD dimensions) record change points, not intervals — so the lookup is inherently an *as-of join*: latest right-row not after the left row's timestamp. The bounded-join + rank-desc + keep-first shape is the portable SQL spelling of it. The equality-join instinct (ON product AND effective_from = order_time) matches almost nothing; the other classic failure is partitioning the rank by product, which crowns one global price and bills every order with it.
ON product AND effective_from = order_time
Solve Price As-Of Order Time yourself →