简体   繁体   中英

Difference between two rows in sql

How to calculate difference between two rows in sql developer?? Scenario is Employee1 has two tasks so I need to calculate the difference between the start date of task1 and finish date of task2 And in 3rd row again Employee2 has two tasks so I need to calculate that difference too. Can someone help me in this please...

If I understand correctly, you want lag() :

select t.*,
       start_date - lag(end_date) over (partition by employee order by start_date) as diff
from t;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM