Home > front end >  Need help on Databricks SQL query
Need help on Databricks SQL query

Time:12-10

Greetings!!

I have a dataset consists of order_number,start_date,staus columns as shown below. enter image description here

from the above table i need an output as single row like shown below. enter image description here

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;
  • Related