Srinivasan Rajasekaran
Srinivasan Rajasekaran

Reputation: 585

SQL End Time as start Time

I have an Table containing data's as follows,

enter image description here

I want them to be seperated as Start Time and End time where the Start and end are same for first row while second row start time is first row End time.

Upvotes: 1

Views: 95

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

You want lag():

select t.*,
       lag(time, 1, time) over (order by time) as starttime,
       time as endtime
from t;

Upvotes: 5

Related Questions