select *
from (
select order_table.date,
order_table.order,
order_table.state,
status_table.status,
row_number() over (partition by status_table.order order by status_table.status_date desc ) rn
from order_table,
status_table
where order_table.order = status_table.order
and status_table.status_date < order_table.date
) sq
where sq.rn = 1
|