Greetings!!
I have a dataset consists of order_number,start_date,staus columns as shown below.
from the above table i need an output as single row like shown below.
in output, i need recent status and first start date.
Can anyone help me with the approach i should follow.?
Please help me. Thanks!
I tried with Dense Rank but getting either recent start date value and old status value.
CodePudding user response:
You need two separate functions for start date and status running over the same window:
SELECT distinct order_id,
first(start_date) over (partition by order_id order by start_date
rows between unbounded preceding and unbounded following) as start_date,
last(status) over (partition by order_id order by start_date
rows between unbounded preceding and unbounded following) as status
FROM a_table;