每个订单的最新状态以及何时设置为该值
Most recent status for each order and when was it set to that value
我正在尝试查找每个订单的最新状态以及设置为该值的时间。我尝试了下面的查询,但结果是 this。我只是希望它显示最新状态而不是全部。太感谢了!
select order_id, updated_at, order_status
from (select order_id,
updated_at,
order_status,
row_number() over(partition by order_id, order_status order by updated_at desc)
as rn
from fishtownanalytics.order_status_history) as x
where rn = 1
只需从分区中删除状态即可
select order_id, updated_at, order_status
from (select order_id,
updated_at,
order_status,
row_number() over(partition by order_id order by updated_at desc)
as rn
from fishtownanalytics.order_status_history) as x
where rn = 1
我正在尝试查找每个订单的最新状态以及设置为该值的时间。我尝试了下面的查询,但结果是 this。我只是希望它显示最新状态而不是全部。太感谢了!
select order_id, updated_at, order_status
from (select order_id,
updated_at,
order_status,
row_number() over(partition by order_id, order_status order by updated_at desc)
as rn
from fishtownanalytics.order_status_history) as x
where rn = 1
只需从分区中删除状态即可
select order_id, updated_at, order_status
from (select order_id,
updated_at,
order_status,
row_number() over(partition by order_id order by updated_at desc)
as rn
from fishtownanalytics.order_status_history) as x
where rn = 1