I need to get “second updated_time” for each order and sorting them by “update_time”. I wrote the following query, which is not giving any output.
Suppose, we have to calculate get the time difference between second updated time and first updated time against each order_id ,if we sort the table on update_time (same question but extended) Server is Mysql. The TIMEDIFF() function will be applied, but how? It am trying this:
select order_history.,order_history.TIMEDIFF( from (select order_history., row_number() OVER (partition by order_id order by update_time) as seqnum from order_history ) order_history where seqnum = 2 order by update_time;
select update_time <MAX(update_time) from order_history order by update_time desc;
[The attached image shows the orders_history (table for the problem)]
I need to get “second updated_time” for each order and sorting them by “update_time”.
This sounds like:
select oh.* from (select oh.*, row_number() over (partition by order_id order by update_toime) as seqnum from order_history oh ) oh where seqnum = 2 order by update_time;